public Guid InsertOrUpdate(Guid ID, Func <Receipt, Receipt> loadFromGUI) { RedBloodDataContext db = new RedBloodDataContext(); Receipt r; if (ID == Guid.Empty) { r = new Receipt(); db.Receipts.InsertOnSubmit(r); } else { r = ReceiptBLL.Get(ID, db); } loadFromGUI(r); //Product In IEnumerable <ReceiptProduct> existingProductCodeInList = r.ReceiptProducts.Where(r1 => r1.Type == ReceiptProduct.TypeX.In); db.ReceiptProducts.DeleteAllOnSubmit( existingProductCodeInList.Where(r1 => !ProductCodeInList.Contains(r1.ProductCode)) ); r.ReceiptProducts.AddRange( ProductCodeInList .Except(existingProductCodeInList.Select(r1 => r1.ProductCode)) .Select(r1 => new ReceiptProduct() { ProductCode = r1, Type = ReceiptProduct.TypeX.In }) ); //Product Out IEnumerable <ReceiptProduct> existingProductCodeOutList = r.ReceiptProducts.Where(r1 => r1.Type == ReceiptProduct.TypeX.Out); db.ReceiptProducts.DeleteAllOnSubmit( existingProductCodeOutList.Where(r1 => !ProductCodeOutList.Contains(r1.ProductCode)) ); r.ReceiptProducts.AddRange( ProductCodeOutList .Except(existingProductCodeOutList.Select(r1 => r1.ProductCode)) .Select(r1 => new ReceiptProduct() { Product = ProductBLL.Get(db, r1), Type = ReceiptProduct.TypeX.Out }) ); db.SubmitChanges(); return(r.ID); }
public static void Add(string DIN, string productCode, int?volume, Pack orgPack = null, DateTime?packDate = null) { RedBloodDataContext db = new RedBloodDataContext(); Donation d = null; if (orgPack == null) { d = DonationBLL.Get4CreateOriginal(db, DIN); } else { d = DonationBLL.Get(DIN); } Product product = ProductBLL.Get(productCode); if (IsExist(DIN, productCode)) { throw new Exception(PackErrEnum.Existed.Message); } //TODO: Check to see valid product code in collection //Code will be here //TODO: Check to see if the pack is collector too late //Code check will be here. Pack pack = new Pack(); pack.DIN = DIN; pack.ProductCode = productCode; pack.Status = Pack.StatusX.Product; pack.Actor = RedBloodSystem.CurrentActor; //pack.Volume = product.OriginalVolume.HasValue ? product.OriginalVolume : defaultVolume; pack.Volume = volume; if (orgPack != null && product.CreatedDateFromOrgPack.HasValue && product.CreatedDateFromOrgPack.Value) { pack.Date = orgPack.Date; } else { if (packDate != null) { pack.Date = packDate; } else { pack.Date = DateTime.Now; } } pack.ExpirationDate = pack.Date.Value.Add(product.Duration.Value - RedBloodSystem.RootTime); db.Packs.InsertOnSubmit(pack); db.SubmitChanges(); PackTransactionBLL.Add(pack.ID, Pack.StatusX.Non, Pack.StatusX.Product, orgPack == null ? PackTransaction.TypeX.In_Collect : PackTransaction.TypeX.In_Product); if (orgPack == null) { DonationBLL.SetOriginalPack(DIN, pack.ID); } }
public static void Add(string DIN, string productCode, Pack orgPack = null) { Product product = ProductBLL.Get(productCode); Add(DIN, productCode, product.OriginalVolume, orgPack); }