public async Task <IActionResult> CreateUpdate(int?id = null) { ViewBag.ExpertiseCategories = await _expertiseService.GetCatrgoriesSelectListAsync(Lng); var model = new ExpertiseCreateUpdateViewModel { Id = id, }; if (id != null) { var expertise = await _expertiseService.GetByIdAsync(id.Value); if (expertise == null) { throw new Exception("Expertise Not Found"); } model = new ExpertiseCreateUpdateViewModel { Id = expertise.Id, Name = expertise.Name, Name_Ku = expertise.Name_Ku, Name_Ar = expertise.Name_Ar, Description = expertise.Description, Description_Ku = expertise.Description_Ku, Description_Ar = expertise.Description_Ar, CategoryId = expertise.ExpertiseCategoryId }; } return(PartialView("CreateUpdate", model)); }
public async Task <IActionResult> CreateUpdate(ExpertiseCreateUpdateViewModel model) { string message; if (model.Id != null) { var expertise = await _expertiseService.GetByIdAsync(model.Id.Value); if (expertise == null) { throw new Exception("Expertise Not Found"); } expertise.Name = model.Name; expertise.Name_Ku = model.Name_Ku; expertise.Name_Ar = model.Name_Ar; expertise.ExpertiseCategoryId = model.CategoryId; expertise.Description = model.Description; expertise.Description_Ar = model.Description_Ar; expertise.Description_Ku = model.Description_Ku; _expertiseService.UpdateExpertise(expertise); message = Messages.ItemUpdatedSuccessFully; } else { var expertise = new Expertise { Name = model.Name, Name_Ku = model.Name_Ku, Name_Ar = model.Name_Ar, ExpertiseCategoryId = model.CategoryId, Description = model.Description, Description_Ku = model.Description_Ku, Description_Ar = model.Description_Ar, CreatedAt = DateTime.Now }; _expertiseService.InsertExpertise(expertise); message = Messages.ItemAddedSuccessFully; } return(Json(new { success = true, message })); }