0

I have around 50 master tables that requires simple and straight forward CRUD operations, my tables are already available in the sql database.

My question is how to make it generic so that I dont need to create manually each individual page for master tables. I saw some ABP CRUDEntityAscyn classes in Boilerplate framework, but I am wondering how to bring it at Presentation layer (.cshtml).

1 Answers1

1

If you need to create an application service that will have Create, Update, Delete, Get, GetAll methods for a specific entity, you can inherit from CrudAppService (or AsyncCrudAppService if you want to create async methods) class to create it easier. CrudAppService base class is generic which gets related Entity and DTO types as generic arguments and is extensible which allows you to override functionality when you need to customize it.

public class Task : Entity, IHasCreationTime
{
    public string Title { get; set; }

    public string Description { get; set; }

    public DateTime CreationTime { get; set; }

    public TaskState State { get; set; }

    public Person AssignedPerson { get; set; }
    public Guid? AssignedPersonId { get; set; }

    public Task()
    {
        CreationTime = Clock.Now;
        State = TaskState.Open;
    }
}

[AutoMap(typeof(Task))]
public class TaskDto : EntityDto, IHasCreationTime
{
    public string Title { get; set; }

    public string Description { get; set; }

    public DateTime CreationTime { get; set; }

    public TaskState State { get; set; }

    public Guid? AssignedPersonId { get; set; }

    public string AssignedPersonName { get; set; }
}

public class TaskAppService : AsyncCrudAppService<Task, TaskDto>
{
    public TaskAppService(IRepository<Task> repository) 
        : base(repository)
    {

    }
}

public interface ITaskAppService : IAsyncCrudAppService<TaskDto>
{

}

public class TaskAppService : AsyncCrudAppService<Task, TaskDto>, ITaskAppService
{
    public TaskAppService(IRepository<Task> repository) 
        : base(repository)
    {

    }
}

calling webapi from client code:

var _editionService = abp.services.app.edition
  _editionService.deleteEdition({
                            id: edition.id
                        }).done(function () {
                            getEditions();
                            abp.notify.success(app.localize('SuccessfullyDeleted'));
                        });

read for more > https://aspnetboilerplate.com/Pages/Documents/Application-Services#crudappservice-and-asynccrudappservice-classes

Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55
  • Thanks for the pointers, I have started reading and implementing on my project, however I am struck at javascript calling the application service method. Not sure where I am going wrong. var _assetService = abp.services.app.asset; //line 1 var _$modal = $('#AssetCreateModal'); var _$form = _$modal.find('form'); line 1 _assetService is undefined when I display on alert at client side using javascript. but abp.services.app.user, & role works fine. Not sure how it is working. – Sudakkar Bhooramoorthy Aug 28 '17 at 14:23
  • ok. i updated my answer and added client-side code. basically you need to do the same in your code. if it works mark as solution. – Alper Ebicoglu Aug 28 '17 at 17:38