public IHttpActionResult Put(string id, [FromBody] AD_AUTONUMBER dataRequest) { try { if (!ModelState.IsValid) { var model = ModelState; string msg = VNPTResources.Instance.Get(model); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = msg })); } var dataItem = this.Repository.GetQuery <AD_AUTONUMBER>().FirstOrDefault(r => r.ID == id); if (dataItem is null) { return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = VNPTResources.Instance.Get(VNPTResources.ID.MsgNotFound) })); } dataItem = dataRequest.Clone(); dataItem.ID = id; this.Repository.Update(dataItem); this.VNPTLogs.Write(this.Repository, EAction.Update, JsonConvert.SerializeObject(dataItem)); this.Repository.UnitOfWork.SaveChanges(); return(Json(new TResult() { Status = (short)EStatus.Ok, Data = dataItem })); } catch (Exception e) { this.VNPTLogs.Write(this.RepositoryLog, e.Message); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = e.Message })); } }
public IHttpActionResult Post([FromBody] AD_AUTONUMBER dataRequest) { try { if (!ModelState.IsValid) { var model = ModelState; string msg = VNPTResources.Instance.Get(model); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = msg })); } if (this.Repository.GetQuery <AD_AUTONUMBER>().Any(r => r.ID.Equals(dataRequest.ID))) { return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = string.Format(VNPTResources.Instance.Get(VNPTResources.ID.MsgErrorIsExists), dataRequest.ID) })); } var dataItem = dataRequest.Clone(); this.Repository.Add(dataItem); this.VNPTLogs.Write(this.Repository, EAction.Insert, JsonConvert.SerializeObject(dataItem)); this.Repository.UnitOfWork.SaveChanges(); return(Json(new TResult() { Status = (short)EStatus.Ok, Data = dataItem })); } catch (Exception e) { this.VNPTLogs.Write(this.RepositoryLog, e.Message); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = e.Message })); } }
public static string GetAutoNumber(IRepository repository, string funcName, long?maxNumber) { string kq = ""; AD_AUTONUMBER ob = repository.GetByKey <AD_AUTONUMBER>(funcName); if (ob != null) { ob = (AD_AUTONUMBER)ob.Clone(); //if (ob.Reset == true) //{ // AD_CONFIG tsNgayDangNhap = repository.GetQuery<AD_CONFIG>().FirstOrDefault(o => funcName.Equals(o.ID)); // if (tsNgayDangNhap == null) // { // tsNgayDangNhap = new AD_CONFIG(); // tsNgayDangNhap.ID = funcName; // tsNgayDangNhap.Name = DateTime.Today.ToString("yyyyMMdd"); // repository.Add(tsNgayDangNhap); // ob.Current = 0; // } // else // { // if (!DateTime.Today.ToString("yyyyMMdd").Equals(tsNgayDangNhap.Name)) // { // tsNgayDangNhap.Name = DateTime.Today.ToString("yyyyMMdd"); // repository.Update(tsNgayDangNhap); // ob.Current = 0; // } // } //} if (ob.Step == 0) { ob.Step = 1; } ob.Current = (maxNumber != null ? maxNumber : ob.Current) + ob.Step; if (string.IsNullOrEmpty(ob.Format)) { ob.Format = string.Empty; kq = (ob.Current).ToString(); } else { //[BN-][$yyyy][-][00000] List <string> lst = new List <string>(); string str = ""; for (int i = 0; i < ob.Format.Length; i++) { if (ob.Format[i] == '[') { str = ""; } else if (ob.Format[i] == ']') { lst.Add(str); } else { str += ob.Format[i]; } } if (lst.Count == 0) { lst.Add(str); } foreach (string s in lst) { if (s.Contains("$")) { string f = s.Replace("$", ""); kq += DateTime.Now.ToString(f); } else if (s.Any(o => o != '0') == false) { kq += ((double)ob.Current).ToString(s); } else { kq += s; } } } repository.Update(ob); } else { ob = new AD_AUTONUMBER() { ID = funcName, Format = "", Current = 1, Step = 1 }; repository.Add(ob); kq += ((double)ob.Current).ToString(ob.Format); } return(kq); }