public JsonResult Action(CategoryActionModel model) { var result = false; JsonResult json = new JsonResult(); if (model.ID > 0) // We try to edit record { var category = CategoryService.Instance.GetCategoriesById(model.ID); category.Name = model.Name; category.Description = model.Description; result = CategoryService.Instance.UpdateCategories(category); } else // We try to create record { Category category = new Category(); category.Name = model.Name; category.Description = model.Description; result = CategoryService.Instance.SaveCategories(category); } if (result) { json.Data = new { Success = true }; } else { json.Data = new { Success = false, Message = "Unable to Perform action on Accomodation type" }; } return(json); }
public ActionResult Delete(int ID) { CategoryActionModel model = new CategoryActionModel(); var category = CategoryService.Instance.GetCategoriesById(ID); model.ID = category.ID; return(PartialView("_Delete", model)); }
public async Task<JsonResult> Action(CategoryActionModel model) { JsonResult result = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet }; var message = ""; bool isSuccess = false; try { if (ModelState.IsValid) { if (model.ID > 0) { _category = _ICategoryService.GetDataById(model.ID); _category.Name = model.Name; _category.Description = model.Description; isSuccess = _ICategoryService.UpdateData(_category); } else { _category.Name = model.Name; _category.Description = model.Description; isSuccess = await Task.Run(() => _ICategoryService.SaveData(_category)); } } else { message = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); } } catch (Exception ex) { message = ex.Message; } if (isSuccess) { message = "Data Save Successfully!!"; result.Data = new { Success = true, Message = message }; } else { result.Data = new { Success = false, Message = message }; } return result; }
public ActionResult Action(int?ID) { CategoryActionModel model = new CategoryActionModel(); if (ID.HasValue)//we are trying to edit record { var category = CategoryService.Instance.GetCategoriesById(ID.Value); model.ID = category.ID; model.Name = category.Name; model.Description = category.Description; } //else no need //{ //} return(PartialView("_Action", model)); }
public JsonResult Delete(CategoryActionModel model) { var result = false; JsonResult json = new JsonResult(); var accomodatioType = CategoryService.Instance.GetCategoriesById(model.ID); result = CategoryService.Instance.DeleteCategories(accomodatioType); if (result) { json.Data = new { Success = true }; } else { json.Data = new { Success = false, Message = "Unable to Perform action on Accomodation type" }; } return(json); }