public ActionResult <CategoryCrud> Delete(CategoryCrud param) { if (param == null) { param = new CategoryCrud(); param._message = _localizer["No parameters."]; return(BadRequest(param)); } try { var model = (from a in _context.Categories where a.CategoryId.Equals(param.CategoryId) select a).FirstOrDefault(); if (model == null) { param._message = _localizer["It has already been deleted."]; return(BadRequest(param)); } _context.Categories.Remove(model); _context.SaveChanges(); ReflectionUtility.Model2Model(model, param); return(Ok(param)); } catch (Exception ex) { param._message = _localizer["System error Please inform system personnel.({0})", ex.Message]; return(BadRequest(param)); } }
public ActionResult <CategoryCrud> Edit([FromBody] CategoryCrud param) { if (param == null) { param = new CategoryCrud(); param._message = _localizer["No parameters."]; return(BadRequest(param)); } //パラメータ項目 param.CategoryId = null; param.CategoryName = null; param.OrderBy = null; //param.ExamineeId = p.ExamineeId; //リスト表示 var list = (from a in _context.Categories where a.ExamineeId.Equals(param.ExamineeId) orderby a.OrderBy select new CategoryList { CategoryId = a.CategoryId, CategoryName = a.CategoryName, ExamineeId = a.ExamineeId, OrderBy = a.OrderBy, } ).ToList(); if (list == null) { param._message = _localizer["It has already been deleted."]; return(BadRequest(param)); } param.CategoryList = list; //オプション情報取得 var options = (from a in _context.Categories where a.ExamineeId.Equals(param.ExamineeId) orderby a.OrderBy ascending select new { a.CategoryId, a.CategoryName }).ToList(); param.Options["categoryIds"] = options; return(Ok(param)); }
public ActionResult <CategoryCrud> Load([FromBody] CategoryCrud param) { if (param == null) { param = new CategoryCrud(); param._message = _localizer["No parameters."]; return(BadRequest(param)); } //オプション情報取得 var options = (from a in _context.Categories where a.ExamineeId.Equals(param.ExamineeId) orderby a.OrderBy ascending select new { a.CategoryId, a.CategoryName }).ToList(); param.Options["categoryIds"] = options; return(Ok(param)); }
public ActionResult <CategoryCrud> Store([FromBody] CategoryCrud param) { if (param == null) { param = new CategoryCrud(); param._message = _localizer["No parameters."]; return(BadRequest(param)); } if (!TryValidateModel(param)) { param._message = _localizer["The input is incorrect."]; return(BadRequest(param)); } //新規の場合 if (param.CategoryId == null || param.CategoryId.Length == 0) { var storeModel = new Category(); ReflectionUtility.Model2Model(param, storeModel); storeModel.CategoryId = (Guid.NewGuid()).ToString(); storeModel.Owner = HttpContext.User.Identity.Name; storeModel.Registed = DateTime.Now; storeModel.Updated = DateTime.Now; storeModel.Version = 1; //登録 _context.Categories.Add(storeModel); _context.SaveChanges(); ReflectionUtility.Model2Model(storeModel, param); } else { var storeModel = (from a in _context.Categories where a.CategoryId.Equals(param.CategoryId) select a).FirstOrDefault(); if (storeModel == null) { param._message = _localizer["It has already been deleted."]; return(BadRequest(param)); } storeModel.CategoryName = param.CategoryName; storeModel.ExamineeId = param.ExamineeId; storeModel.OrderBy = param.OrderBy; storeModel.Updated = DateTime.Now; storeModel.Version += 1; //登録 _context.Categories.Update(storeModel); _context.SaveChanges(); ReflectionUtility.Model2Model(storeModel, param); } //オプション情報取得 var options = (from a in _context.Categories where a.ExamineeId.Equals(param.ExamineeId) orderby a.OrderBy ascending select new { Value = a.CategoryId, Text = a.CategoryName }).ToList(); param.Options["categoryIds"] = options; return(Ok(param)); }