public bool UpdateProductRateGroupForDesign(int ProductGroupId, int ProductRateGroupId, 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.ProductProcess join t in db.RateListHeader on p.ProcessId equals t.ProcessId where t.RateListHeaderId == RateListHeaderId && ProductIds.Contains(p.ProductId) select p).ToList(); foreach (var item in ExistingProducts) { ProductProcess ExRec = Mapper.Map <ProductProcess>(item); item.ProductRateGroupId = ProductRateGroupId; item.ModifiedBy = User; item.ModifiedDate = DateTime.Now; LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = item, }); item.ObjectState = Model.ObjectState.Modified; db.ProductProcess.Add(item); } Modifications = new ModificationsCheckService().CheckChanges(LogList); try { db.SaveChanges(); } catch (Exception ex) { return(false); } return(true); }
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); }