public JsonResult Update([FromBody] AssetCancelHeadersJtableModel obj) { var msg = new JMessage { Error = false, Title = "" }; try { var data = _context.AssetCancelHeaders.FirstOrDefault(x => x.AssetID == obj.AssetID); data.Title = obj.Title; data.Branch = obj.Branch; data.Person = obj.Person; data.Note = obj.Note; data.Status = obj.Status; data.CancelTime = !string.IsNullOrEmpty(obj.CancelTime) ? DateTime.ParseExact(obj.CancelTime, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null; data.UpdatedTime = DateTime.Now.Date; data.UpdatedBy = ESEIM.AppContext.UserName; _context.AssetCancelHeaders.Update(data); _context.SaveChanges(); msg.Title = "Cập nhật phiếu điều chuyển thành công"; } catch (Exception) { msg.Error = true; msg.Title = "Có lỗi khi cập nhật phiếu điều chuyển"; } return(Json(msg)); }
public JsonResult Insert([FromBody] AssetCancelHeadersJtableModel obj) { var msg = new JMessage { Title = "", Error = false }; try { DateTime?CancelTime = !string.IsNullOrEmpty(obj.CancelTime) ? DateTime.ParseExact(obj.CancelTime, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null; var data = _context.AssetCancelHeaders.FirstOrDefault(x => x.TicketCode == obj.TicketCode && x.IsDeleted == false); if (data == null) { var dt = new AssetCancelHeader(); dt.Quantity = obj.Quantity; dt.TicketCode = obj.TicketCode; dt.Title = obj.Title; dt.Branch = obj.Branch; dt.Person = obj.Person; dt.Note = obj.Note; dt.Status = obj.Status; dt.CancelTime = CancelTime; dt.CreatedBy = ESEIM.AppContext.UserName; dt.CreatedTime = DateTime.Now; _context.AssetCancelHeaders.Add(dt); _context.SaveChanges(); msg.Title = String.Format(CommonUtil.ResourceValue("SUCCESS") /*, CommonUtil.ResourceValue("DCD_MSG_TITLE_DCD")*/); } else { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("OK"));/*DCD_MSG_DOCUMENT_NOT*/ } } catch (Exception) { msg.Error = true; // msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_FAILED")/*, CommonUtil.ResourceValue("DCD_MSG_TITLE_DCD")*/); msg.Title = "Lỗi"; } return(Json(msg)); }