public void Delete(SalesComplex model) { #region 邏輯驗證 if (model == null)//沒有資料 { throw new Exception("MessageNoData".ToLocalized()); } #endregion #region 變為Models需要之型別及邏輯資料 var info = Mapper.Map <Sales>(model.Sales); #endregion #region Models資料庫 foreach (SalesDetailViewModel t in model.ChildList) { var d = Mapper.Map <SalesDetail>(t); _DetailRepository.Delete(d); } this._Repository.Delete(info); this._UnitOfWork.SaveChange(); #endregion }
public SalesComplex Get(string id) { SalesComplex info = new SalesComplex(); info = this.GetAll().Where(x => x.Sales.SalesID == id).Single(); return(info); }
public SalesComplex Create(SalesComplex source) { #region 取資料 #endregion #region 邏輯驗證 #endregion #region 變為Models需要之型別及邏輯資料 Sales main = GetSalesOnCreate(source); List <SalesDetail> children = GetChildOnCreate(main, source); #endregion #region Models資料庫 this._Repository.Create(main); foreach (SalesDetail item in children) { this._DetailRepository.Create(item); } this._UnitOfWork.SaveChange(); #endregion return(this.Get(main.SalesID)); }
public ActionResult DeleteConfirmed(SalesComplex model) { ResultModel result = new ResultModel(); try { #region Service資料庫 if (this._SalesComplexService.IsUsed(model)) { result.Message = "MessageChaneDelete2UpdateComplete".ToLocalized(); model.Sales.Activate = YesNo.No.Value; this._SalesComplexService.Update(model); } else { this._SalesComplexService.Delete(model); } #endregion } catch (Exception ex) { #region 錯誤時錯誤訊息 result.Status = false; result.Message = ex.Message.ToString(); #endregion } return(Json(result)); }
private Sales GetSalesOnUpdate(SalesComplex source) { Sales info = Mapper.Map <Sales>(source.Sales); info.LastPerson = IdentityService.GetUserData().UserID; info.LastUpdate = DateTime.Now; return(info); }
public bool IsUsed(SalesComplex info) { //var query = this._Repository.Get(x => x.InquiryID == model.Inquiry.InquiryID); //var result = query.Product.Any(); //this._Repository.HandleDetached(query); // //return result; return(true); // 目前不知關聯到哪些資料表 }
private Sales GetSalesOnCreate(SalesComplex source) { Sales info = Mapper.Map <Sales>(source.Sales); // 取得詢價單號;目前由使用者自型輸入 info.SalesID = GenerateSalesID(info); //info.PostingTime = DateTime.Today; info.LastPerson = IdentityService.GetUserData().UserID; info.LastUpdate = DateTime.Now; return(info); }
private List <SalesDetail> GetChildOnCreate(Sales master, SalesComplex source) { List <SalesDetail> infos = new List <SalesDetail>(); var wanted = source.ChildList.Where(x => x.IsDirty == true); foreach (var item in wanted) { SalesDetail temp = Mapper.Map <SalesDetail>(item); temp.SalesID = master.SalesID; temp.LastPerson = IdentityService.GetUserData().UserID; temp.LastUpdate = DateTime.Now; infos.Add(temp); } return(infos); }
private void InitViewBag(SalesComplex info) { // 倉庫 ViewBag.WareHouseList = new SelectList(this._GlobalService.GetWarehouseList(), "Key", "Value", info?.Sales.WarehouseID); // 公司 ViewBag.CompanyList = new SelectList(this._GlobalService.GetCustomerList(), "Value", "Display", info?.Sales?.CustomerID); // 運送方式 ViewBag.ShippingModeList = new SelectList(this._GlobalService.GetShippingModeList(), "Key", "Value", null); ViewBag.MultiWareHouseList = new SelectList(this._GlobalService.GetWarehouseList(), "Key", "Value", null); ViewBag.YseNoList = new SelectList(YesNo.GetAll(), "value", "Text", info?.Sales.Activate); }
public void Update(SalesComplex source) { #region 取資料 #endregion #region 邏輯驗證 #endregion #region 變為Models需要之型別及邏輯資料 Sales main = GetSalesOnUpdate(source); List <SalesDetail> children = GetChildOnCreate(main, source); #endregion #region Models資料庫 this._Repository.Update(main); foreach (SalesDetail item in children) { if (item.SeqNo == 0) { this._DetailRepository.Create(item); } else { this._DetailRepository.Update(item); } } this._UnitOfWork.SaveChange(); #endregion }
public ActionResult Edit(SalesComplex info) { ResultModel result = new ResultModel(); try { #region 驗證Model if (!ModelState.IsValid) { throw new Exception(ModelStateErrorClass.FormatToString(ModelState)); } // 至少需有一筆明細資料 if (info.ChildList == null || info.ChildList.Count == 0) { ModelState.AddModelError("ChildList", "至少需有一筆明細資料。"); } else { var query = info.ChildList .GroupBy(x => x.ProductID) .ToDictionary(x => x.Key, x => x.Count()) .Where(x => x.Value > 1) .ToList(); CDMS.Web.Common.DuplicateValidator validator = new CDMS.Web.Common.DuplicateValidator(query); if (validator.Message.Count > 0) { foreach (var s in validator.Message) { ModelState.AddModelError("ChildList", s); } } } if (!ModelState.IsValid) { string message = ModelStateErrorClass.FormatToString(ModelState); result.Status = false; result.Message = message; return(Json(result)); } #endregion #region 前端資料變後端用資料ViewModel時用 #endregion #region Service資料庫 this._SalesComplexService.Update(info); #endregion #region 息頁面設定 result.Status = true; result.CloseWindow = false; result.Url = Url.Action("Edit", new { id = info.Sales.SalesID }); result.Message = "MessageComplete".ToLocalized(); #endregion } catch (Exception ex) { #region 錯誤時錯誤訊息 result.Status = false; result.Message = ex.Message.ToString(); #endregion } return(Json(result)); }