public void Save(string uid) { try { if (string.IsNullOrEmpty(uid)) { throw new ArgumentNullException("UID", "User Name is required."); } Dictionary <string, string> ValErrors = Validate(); if (ValErrors.Count > 0) { throw new RequisitionNotValidException("Purchase Order is not valid.", ValErrors); } using (PurchasingContext Context = ContextHelper.GetDBContext()) { Enums.HistoryType ChangeType; PurchaseOrder Original = null; PurchaseOrderData data = null; if (PurchaseOrderID > 0) { ChangeType = Enums.HistoryType.UPDATE; data = Context.PurchaseOrderDatas.FirstOrDefault(x => x.purchase_order_id == PurchaseOrderID); Original = new PurchaseOrder(data); } else { ChangeType = Enums.HistoryType.ADD; data = new PurchaseOrderData(); data.created_by = uid; data.date_created = DateTime.Now; } data.vendor_id = VendorID; data.purchase_order_type_luid = PurchaseOrderTypeLUID; data.organization_id = OrganizationID; if (DateOrdered > DateTime.MinValue) { data.date_ordered = DateOrdered; } else { data.date_ordered = null; } if (OrderedByID > 0) { data.ordered_by = OrderedByID; } else { data.ordered_by = null; } data.status_luid = StatusLUID; if (DateReceived > DateTime.MinValue) { data.date_received = DateReceived; } else { data.date_received = null; } if (DateClosed > DateTime.MinValue) { data.date_closed = DateClosed; } else { data.date_closed = null; } if (!String.IsNullOrEmpty(ShipToName)) { data.ship_to_name = ShipToName; } else { data.ship_to_name = null; } if (!String.IsNullOrEmpty(ShipToAttn)) { data.ship_to_attention = ShipToAttn; } else { data.ship_to_attention = null; } if (ShipToAddress != null && ShipToAddress.IsValid()) { data.ship_to_address = ShipToAddress.ToArenaFormat(); } else { data.ship_to_address = null; } if (ShippingCharge != 0) { data.shipping_charge = ShippingCharge; } else { data.shipping_charge = null; } if (OtherCharge != 0) { data.other_charge = OtherCharge; } else { data.other_charge = null; } if (DefaultPaymentMethodID > 0) { data.default_payment_method_id = DefaultPaymentMethodID; } else { data.default_payment_method_id = null; } data.modified_by = uid; data.date_modified = DateTime.Now; data.active = Active; if (!String.IsNullOrEmpty(Terms)) { data.terms = Terms.Trim(); } else { data.terms = null; } data.has_been_billed = HasBeenBilled; if (PurchaseOrderID <= 0) { Context.PurchaseOrderDatas.InsertOnSubmit(data); } Context.SubmitChanges(); Load(data); SaveHistory(ChangeType, Original, uid); } } catch (Exception ex) { throw new RequisitionException("An error has occurred while saving purchase order.", ex); } }
public bool HasChanged() { bool IsDifferent = false; PurchaseOrder Original = new PurchaseOrder(PurchaseOrderID); if (VendorID != Original.VendorID) { IsDifferent = true; } if (!IsDifferent && PurchaseOrderTypeLUID != Original.PurchaseOrderTypeLUID) { IsDifferent = true; } if (!IsDifferent && OrganizationID != Original.OrganizationID) { IsDifferent = true; } if (!IsDifferent && DateOrdered != Original.DateOrdered) { IsDifferent = true; } if (!IsDifferent && OrderedByID != Original.OrderedByID) { IsDifferent = true; } if (!IsDifferent && StatusLUID != Original.StatusLUID) { IsDifferent = true; } if (!IsDifferent && DateReceived != Original.DateReceived) { IsDifferent = true; } if (!IsDifferent && DateClosed != Original.DateClosed) { IsDifferent = true; } if (!IsDifferent && ShipToAddress != Original.ShipToAddress) { IsDifferent = true; } if (!IsDifferent && ShipToName != Original.ShipToName) { IsDifferent = true; } if (!IsDifferent && ShipToAttn != Original.ShipToAttn) { IsDifferent = true; } if (!IsDifferent && ShippingCharge != Original.ShippingCharge) { IsDifferent = true; } if (!IsDifferent && OtherCharge != Original.OtherCharge) { IsDifferent = true; } if (!IsDifferent && DefaultPaymentMethodID != Original.DefaultPaymentMethodID) { IsDifferent = true; } if (!IsDifferent && Terms != Original.Terms) { IsDifferent = true; } return(IsDifferent); }
public bool CanBeDeleted() { bool Deleteable = true; if (Deleteable && POItems.Where(poi => poi.Active == true).Where(poi => poi.PurchaseOrder.Active).Where(poi => poi.PurchaseOrder.StatusLUID != PurchaseOrder.PurchaseOrderStatusCancelledLUID()).Count() > 0) { Deleteable = false; } return(Deleteable); }