public JsonResult AddNew() { string Code = this.Request["Code"]; string Name = this.Request["Name"]; string Description = this.Request["Description"]; string ShiftType = this.Request["ShiftType"]; string Points = this.Request["Lines"]; List <string> ErrorList = new List <string>(); if (string.IsNullOrEmpty(Code)) { //return Json(new { success = false, msg = "Code can not be empty!" }); throw new BaseException("Code can not be empty!"); } if (string.IsNullOrEmpty(Name)) { throw new BaseException("Name can not be empty!"); } if (string.IsNullOrEmpty(Points)) { return(Json(new { success = false, msg = "Points param is null or empty!" })); } JObject json = JObject.Parse(Points); var result = from point in json["data"].Children() select new ShiftPoint.DTO { IndexNumber = point.Value <int>("IndexNumber"), Name = point.Value <string>("Name"), PointTime = point.Value <string>("PointTime"), Before = point.Value <string>("Before"), After = point.Value <string>("After"), PointType = point.Value <string>("PointType"), Description = point.Value <string>("Description") }; ShiftDef.DTO head = new ShiftDef.DTO { Code = Code, Name = Name, ShiftType = ShiftType, Description = Description }; ShiftDef.AddNewShiftDef(head, result.ToList()); var resultSuccess = new { success = true, msg = "New shiftdef saved!" }; return(Json(resultSuccess)); }
public JsonResult AddNew() { string Code = HttpContext.Request["Code"]; string Name = HttpContext.Request["Name"]; string Description = HttpContext.Request["Description"]; string FromDate = HttpContext.Request["FromDate"]; string ToDate = HttpContext.Request["ToDate"]; string Rules = HttpContext.Request["Rules"]; List <string> ErrorList = new List <string>(); if (string.IsNullOrEmpty(Code)) { return(Json(new { success = false, msg = "Code can not be empty!" })); } if (string.IsNullOrEmpty(Name)) { return(Json(new { success = false, msg = "Name can not be empty!" })); } if (string.IsNullOrEmpty(Points)) { return(Json(new { success = false, msg = "Points param is null or empty!" })); } ShiftDef.DTO head = new ShiftDef.DTO { Code = Code, Name = Name, ShiftType = string.IsNullOrEmpty(ShiftType) ? -1 : int.Parse(ShiftType), Description = Description }; JObject json = JObject.Parse(Points); var result = from point in json["data"].Children() select new ShiftPoint.DTO { IndexNumber = point.Value <int>("IndexNumber"), Name = point.Value <string>("Name"), PointTime = point.Value <string>("PointTime"), PointType = point.Value <int>("PointType"), Description = point.Value <string>("Description") }; ShiftDef.AddNewShiftDef(head, result.ToList()); var resultSuccess = new { success = true, msg = "New shiftdef saved!" }; return(Json(resultSuccess)); }