public JsonResult LoadDetailCategory(int id) { Response response; try { using (var db = new KiaGalleryContext()) { var entity = db.CategoryInventoryReportMember.Single(x => x.Id == id); var data = new CategoryInventoryReportViewModel() { id = entity.Id, title = entity.Title, order = entity.Order, active = entity.Active, }; response = new Response() { status = 200, data = data, }; } } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveCategory(CategoryInventoryReportViewModel model) { Response response; try { int status = 200; string message = string.Empty; using (var db = new KiaGalleryContext()) { int userId = GetAuthenticatedUserId(); if (model.id != null && model.id > 0) { var entity = db.CategoryInventoryReportMember.Single(x => x.Id == model.id); entity.Order = model.order; entity.Title = model.title; entity.Active = model.active; entity.ModifyUserId = userId; entity.ModifyDate = DateTime.Now; message = "دسته بندی با موفقیت ویرایش شد."; } else { var entity = new CategoryInventoryReportMember() { Title = model.title, Order = model.order, Active = model.active, CreateUserId = userId, ModifyUserId = userId, CreateDate = DateTime.Now, ModifyDate = DateTime.Now, }; db.CategoryInventoryReportMember.Add(entity); message = "دسته بندی با موفقیت ایجاد شد."; } db.SaveChanges(); } response = new Response() { status = status, message = message }; } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }