public ActionResult Submitted(int Id, string returl, string UserRemark) { if (ModelState.IsValid) { RateListHeader Header = _RateListHeaderService.Find(Id); int ActivityType; var Cartesian = (from p in db.RateListHeader join t in db.RateListPersonRateGroup on p.RateListHeaderId equals t.RateListHeaderId into table from tab in table.DefaultIfEmpty() join t1 in db.RateListProductRateGroup on p.RateListHeaderId equals t1.RateListHeaderId into table2 from tab2 in table2.DefaultIfEmpty() where p.RateListHeaderId == Id select new { RateListHId = p.RateListHeaderId, ProdRateGroupId = (int?)tab2.ProductRateGroupId, PerRateGroupId = (int?)tab.PersonRateGroupId, }).ToList(); var ExistingRateList = (from p in db.RateListLine where p.RateListHeaderId == Id select p).ToList(); var PedingToUpdate = (from p in Cartesian join t in ExistingRateList on new { x = p.RateListHId, y = p.ProdRateGroupId, z = p.PerRateGroupId } equals new { x = t.RateListHeaderId, y = t.ProductRateGroupId, z = t.PersonRateGroupId } into g from tab in g.DefaultIfEmpty() where tab == null select p).ToList(); var PendingToDelete = (from p in ExistingRateList join t in Cartesian on new { x = p.RateListHeaderId, y = p.ProductRateGroupId, z = p.PersonRateGroupId } equals new { x = t.RateListHId, y = t.ProdRateGroupId, z = t.PerRateGroupId } into g from tab in g.DefaultIfEmpty() where tab == null && p.ProductId == null select p ).ToList(); foreach (var item in PedingToUpdate) { RateListLine Line = new RateListLine(); Line.RateListHeaderId = item.RateListHId; Line.PersonRateGroupId = item.PerRateGroupId; Line.ProductRateGroupId = item.ProdRateGroupId; Line.CreatedBy = User.Identity.Name; Line.CreatedDate = DateTime.Now; Line.ModifiedBy = User.Identity.Name; Line.ModifiedDate = DateTime.Now; Line.ObjectState = Model.ObjectState.Added; db.RateListLine.Add(Line); } foreach (var item in PendingToDelete) { item.ObjectState = Model.ObjectState.Deleted; db.RateListLine.Remove(item); } Header.Status = (int)StatusConstants.Submitted; ActivityType = (int)ActivityTypeContants.Submitted; //_StockHeaderService.Update(StokHeader); Header.ObjectState = Model.ObjectState.Modified; db.RateListHeader.Add(Header); try { db.SaveChanges(); db.Dispose(); } catch (Exception Ex) { string message = _exception.HandleException(Ex); ModelState.AddModelError("", message); return(RedirectToAction("Index").Danger("Error in creating RateList.")); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.RateListHeader).DocumentTypeId, DocId = Header.RateListHeaderId, ActivityType = (int)ActivityTypeContants.Submitted, DocNo = Header.RateListName, UserRemark = UserRemark, })); return(RedirectToAction("RateListWizard", new { id = Id })); } return(View()); }
public void Update(RateListLine s) { s.ObjectState = ObjectState.Modified; _unitOfWork.Repository <RateListLine>().Update(s); }
public void Delete(RateListLine s) { _unitOfWork.Repository <RateListLine>().Delete(s); }
public RateListLine Create(RateListLine s) { s.ObjectState = ObjectState.Added; _unitOfWork.Repository <RateListLine>().Insert(s); return(s); }
public bool UpdateRateListLineForProduct(int ProductId, decimal Rate, decimal Loss, decimal Weight, int RateListHeaderId, string User, out XElement Modifications) { Modifications = null; if (ProductId == 0) { return(false); } List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); var ExistingProducts = (from p in db.RateListLine where p.RateListHeaderId == RateListHeaderId && p.ProductId == ProductId select p).FirstOrDefault(); if (ExistingProducts == null) { RateListLine Rll = new RateListLine(); Rll.ProductId = ProductId; Rll.Rate = Rate; Rll.Loss = Loss; Rll.UnCountedQty = Weight; Rll.RateListHeaderId = RateListHeaderId; Rll.ModifiedBy = User; Rll.CreatedBy = User; Rll.ModifiedDate = DateTime.Now; Rll.CreatedDate = DateTime.Now; Rll.ObjectState = Model.ObjectState.Added; db.RateListLine.Add(Rll); LogList.Add(new LogTypeViewModel { ExObj = Rll, }); } else { RateListLine ExRec = Mapper.Map <RateListLine>(ExistingProducts); ExistingProducts.Rate = Rate; ExistingProducts.Loss = Loss; ExistingProducts.UnCountedQty = Weight; ExistingProducts.ModifiedBy = User; ExistingProducts.ModifiedDate = DateTime.Now; ExistingProducts.ObjectState = Model.ObjectState.Modified; db.RateListLine.Add(ExistingProducts); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = ExistingProducts, }); } Modifications = new ModificationsCheckService().CheckChanges(LogList); try { db.SaveChanges(); } catch (Exception ex) { return(false); } return(true); }
public bool UpdateRateListLineForDesign(int ProductGroupId, decimal Rate, decimal Loss, decimal Weight, int RateListHeaderId, string User, out XElement Modifications) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); var Products = (from p in db.Product where p.ProductGroupId == ProductGroupId select p).ToList(); var ProductIds = Products.Select(m => m.ProductId).ToArray(); var ExistingProducts = (from p in db.RateListLine where p.RateListHeaderId == RateListHeaderId && ProductIds.Contains(p.ProductId.Value) select p).ToList(); var PendingToCreate = (from p in ProductIds join t in ExistingProducts on p equals t.ProductId into table from tab in table.DefaultIfEmpty() where tab == null select p).ToList(); foreach (var item in PendingToCreate) { RateListLine Rll = new RateListLine(); Rll.ProductId = item; Rll.Rate = Rate; Rll.Loss = Loss; Rll.UnCountedQty = Weight; Rll.RateListHeaderId = RateListHeaderId; Rll.ModifiedBy = User; Rll.CreatedBy = User; Rll.ModifiedDate = DateTime.Now; Rll.CreatedDate = DateTime.Now; Rll.ObjectState = Model.ObjectState.Added; db.RateListLine.Add(Rll); LogList.Add(new LogTypeViewModel { ExObj = Rll, }); } foreach (var item in ExistingProducts) { RateListLine ExRec = Mapper.Map <RateListLine>(item); item.Rate = Rate; item.Loss = Loss; item.UnCountedQty = Weight; item.ModifiedBy = User; item.ModifiedDate = DateTime.Now; item.ObjectState = Model.ObjectState.Modified; db.RateListLine.Add(item); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = item, }); } Modifications = new ModificationsCheckService().CheckChanges(LogList); try { db.SaveChanges(); } catch (Exception ex) { return(false); } return(true); }