public static void DeepCopySupplierProperties(Supplier fromSupplier, Supplier toSupplier) { toSupplier.IsActive = fromSupplier.IsActive; toSupplier.Name = fromSupplier.Name; toSupplier.Address = fromSupplier.Address; toSupplier.GSTID = fromSupplier.GSTID; }
public Supplier Add(Supplier supplier) { this.suppliers.Add(supplier); this.suppliers.SaveChanges(); return supplier; }
public Supplier Update(int id, Supplier supplier) { var supplierToUpdate = this.suppliers.GetById(id); supplierToUpdate.Name = supplier.Name; this.suppliers.SaveChanges(); return supplierToUpdate; }
private static LedgerAccount CreateSupplierLedgerAccount(Supplier supplier) { return new LedgerAccount { Name = supplier.Name + " Accounts Payable", Notes = "Accounts Payable", Class = "Liability" }; }
public void SuppliersControllerEditActionShouldRenderProperView() { var suppliersServicesMock = new Mock<ISuppliersServices>(); var supplier = new Supplier { Name = "Delete me" }; suppliersServicesMock.Setup(x => x.Update(It.IsAny<int>(), supplier)); var controller = new SuppliersController(suppliersServicesMock.Object); controller.WithCallTo(x => x.Edit(123)).ShouldRenderView("Edit"); }
private static void CreateAndAddSupplierLedgerToDatabaseContext(ERPContext context, Supplier suppplier) { var ledgerAccount = CreateSupplierLedgerAccount(suppplier); context.Ledger_Accounts.Add(ledgerAccount); var ledgerGeneral = CreateSupplierLedgerGeneral(ledgerAccount); context.Ledger_General.Add(ledgerGeneral); var ledgerAccountBalance = CreateSupplierLedgerAccountBalance(ledgerAccount); context.Ledger_Account_Balances.Add(ledgerAccountBalance); }
public static void SaveSupplierEditsToDatabase(Supplier editingSupplier, Supplier editedSupplier) { using (var ts = new TransactionScope()) { var context = new ERPContext(); if (!IsSupplierNameChange(editingSupplier, editedSupplier)) ChangeSupplierLedgerAccountNameInDatabaseContext(context, editingSupplier, editedSupplier); SaveSupplierEditsToDatabaseContext(context, editingSupplier, editedSupplier); ts.Complete(); } }
public void DeleteSupplier(SupplierEditViewData data) { Supplier sup = new Supplier() { SupplierID = data.SupplierID, SupplierName = data.SupplierName, City = data.City, CompanyAddress = data.CompanyAddress, Email = data.Email, Fax = data.Fax, TelephoneNumber = data.TelephoneNumber, ZipCode = data.ZipCode }; supRep.DeleteSupplier(sup); context_db.SaveChanges(); Messenger.NotifyColleagues(MessageTypes.MSG_SUPPLIER_DELETED, data); }
public static void AddSupplierAlongWithItsLedgerToDatabase(Supplier supplier) { var context = new ERPContext(); try { context.Suppliers.Add(supplier); CreateAndAddSupplierLedgerToDatabaseContext(context, supplier); context.SaveChanges(); } catch { MessageBox.Show("The supplier's name is already being used.", "Invalid Supplier", MessageBoxButton.OK); } finally { context.Dispose(); } }
private static bool IsSupplierNameChange(Supplier editingSupplier, Supplier editedSupplier) { return editingSupplier.Name == editedSupplier.Name; }
private static void SaveSupplierEditsToDatabaseContext(ERPContext context, Supplier editingSupplier, Supplier editedSupplier) { context.Entry(editingSupplier).State = EntityState.Modified; DeepCopySupplierProperties(editedSupplier, editingSupplier); context.SaveChanges(); }
private static LedgerAccount GetSupplierLedgerAccountFromDatabaseContext(ERPContext context, Supplier supplier) { var searchName = supplier.Name + " Accounts Payable"; return context.Ledger_Accounts.First(e => e.Name.Equals(searchName)); }
private static void ChangeSupplierLedgerAccountNameInDatabaseContext(ERPContext context, Supplier editingSupplier, Supplier editedSupplier) { var ledgerAccountFromDatabase = GetSupplierLedgerAccountFromDatabaseContext(context, editingSupplier); ledgerAccountFromDatabase.Name = $"{editedSupplier.Name} Accounts Payable"; context.SaveChanges(); }
public void InsertSupplier(SupplierInsertViewData data) { Supplier sup = new Supplier() { SupplierName = data.SupplierName, City = data.City, Email = data.Email, TelephoneNumber = data.TelephoneNumber, }; supRep.InsertAction(sup); context_db.SaveChanges(); Messenger.NotifyColleagues(MessageTypes.MSG_SUPPLIER_INSERTED, data); }