public int NewInvoice(int BusinessNumber, int CustomerNumber) { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { var business = new BusinessAccount(BusinessNumber); var customer = new Customer(CustomerNumber); var newInvoice = new Invoice { CreationDate = DateTime.Now, BusinessNumber = business.BusinessNumber, BusinessName = business.BusinessName, BusinessOwner = business.BusinessOwner, PhoneNumber = business.PhoneNumber, Email = business.Email, Website = business.Website, Logo = business.Logo, ABN = business.ABN, CustomerId = customer.CustomerId, Tax = (decimal)3.00, CustomerName = customer.CustomerName, CustomerAddress = customer.CustomerAddress, CustomerPhone = customer.CustomerPhoneNumber, CustomerEmail = customer.CustomerEmail, }; context.Invoices.Add(newInvoice); context.SaveChanges(); return(newInvoice.InvoiceNumber); } }
public static void AddInvoiceItem(int id, int option, FormCollection collection)//Clean up { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { var formItemNumber = Int32.Parse(collection["ItemNumber"]); var itemForName = context.Items.Where(x => x.ItemNumber == formItemNumber).First(); var newInvoiceItem = new InvoiceItem { InvoiceId = option, ItemId = Int32.Parse(collection["ItemNumber"]), ItemQuantity = Int32.Parse(collection["ItemQuantity"]), ItemName = itemForName.ItemName, }; context.InvoiceItems.Add(newInvoiceItem); context.SaveChanges(); var orderItems = context.InvoiceItems.Where(x => x.InvoiceId == option).ToList(); var subtotal = (decimal)0.00; foreach (var item in orderItems) { //returning nothing? var itemCost = context.Items.Where(x => x.ItemNumber == item.ItemId).First(); System.Diagnostics.Debug.WriteLine("Item Is:"); System.Diagnostics.Debug.WriteLine(itemCost); var quantity = item.ItemQuantity; var cost = itemCost.Cost; var totalCost = cost * quantity; subtotal += totalCost; } var invoice = context.Invoices.Where(x => x.InvoiceNumber == option).FirstOrDefault(); // calculate and save total/tax var tax = (decimal)0.00; tax = Decimal.Parse(collection["taxRate"]); invoice.Tax = tax; var total = subtotal + ((subtotal / 100) * tax); invoice.SubTotal = subtotal; invoice.TotalCost = total; context.SaveChanges(); } }
public static void DeleteBusiness(int id) { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { var business = new BusinessAccount(id); context.BusinessAccounts.Attach(business); context.BusinessAccounts.Remove(business); context.SaveChanges(); } }
public static void InvoiceCreate(int id, int option, FormCollection collection) { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { var notes = collection["Notes"]; var invoice = context.Invoices.Where(x => x.InvoiceNumber == option).FirstOrDefault(); invoice.Notes = notes; invoice.invoiceComplete = true; context.SaveChanges(); } }
public static void RemoveInvoiceItem(int id, FormCollection collection) { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { var invoiceID = Int32.Parse(collection["removeItem"]); var invoiceItem = context.InvoiceItems.Where(x => x.InvoiceItemId == invoiceID).FirstOrDefault(); context.InvoiceItems.Attach(invoiceItem); context.InvoiceItems.Remove(invoiceItem); context.SaveChanges(); } }
public Item(int id, FormCollection collection) { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { BusinessNumber = id; ItemName = collection["ItemName"]; ItemDescription = collection["ItemDescription"]; Cost = Decimal.Parse(collection["Cost"]); context.Items.Add(this); context.SaveChanges(); } }
public static void InvoiceDelete(int id) { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { var invoice = new Invoice { InvoiceNumber = id }; context.Invoices.Attach(invoice); context.Invoices.Remove(invoice); context.SaveChanges(); var model = context.Invoices.Where(x => x.InvoiceNumber == id).FirstOrDefault(); } }
public Customer(int BusinessNumber, string CustomerName, string CustomerAddress, string CustomerPhoneNumber, string CustomerEmail) { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { var customer = new Customer(); this.BusinessNumber = BusinessNumber; this.CustomerName = CustomerName; this.CustomerAddress = CustomerAddress; this.CustomerPhoneNumber = CustomerPhoneNumber; this.CustomerEmail = CustomerEmail; context.Customers.Add(this); context.SaveChanges(); } }
public BusinessAccount(FormCollection collection, string userID) { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { this.BusinessName = collection["BusinessName"]; this.BusinessOwner = collection["BusinessOwner"]; this.PhoneNumber = collection["PhoneNumber"]; this.Email = collection["Email"]; this.Website = collection["Website"]; this.Logo = collection["Logo"]; this.ABN = collection["ABN"]; this.UserAccount = userID; context.BusinessAccounts.Add(this); context.SaveChanges(); } }
public static void UpdateBusiness(FormCollection collection, int businessNumber) { using (CustomerManagementSystemContext context = new CustomerManagementSystemContext()) { var business = context.BusinessAccounts.Where(x => x.BusinessNumber == businessNumber).FirstOrDefault(); if (collection["BusinessName"] != null) { business.BusinessName = collection["BusinessName"]; } if (collection["BusinessOwner"] != null) { business.BusinessOwner = collection["BusinessOwner"]; } if (collection["PhoneNumber"] != null) { business.PhoneNumber = collection["PhoneNumber"]; } if (collection["Email"] != null) { business.Email = collection["Email"]; } if (collection["Website"] != null) { business.Website = collection["Website"]; } if (collection["Logo"] != null) { business.Logo = collection["Logo"]; } if (collection["ABN"] != null) { business.ABN = collection["ABN"]; } context.SaveChanges(); } }