public static async Task<Utils.Messages.Response> AddEntityAsync(EntityAddEditModel entityModel) { var response = new Response(); var context = new AdminDbContext(); ValidateEntity(entityModel, response); if (!response.Success) { return response; } else { var entity = new Entity(); entity.TypeId = entityModel.TypeId; entity.Name = entityModel.Name; context.Entities.Add(entity); await context.SaveChangesAsync(); } return response; }
public async Task<JsonResult> AddEntity(EntityAddEditModel entity) { Quince.Utils.Messages.Response response = await EntityManager.AddEntityAsync(entity); return Json(response); }
public static Response ValidateEntity(EntityAddEditModel entity, Response response = null) { response = response ?? new Response(); if (string.IsNullOrEmpty(entity.Name)) { response.AddMessage(false, "The name should not be empty", ResponseMessageType.Warning); } if (entity.TypeId == 0) { response.AddMessage(false, "Select an Entity Type", ResponseMessageType.Warning); } return response; }