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);
            }
        }
예제 #2
0
 //make a constructor that takes in a businessnumber and customernumber and constructs invoice
 public Invoice([Optional] int id)
 {
     this.InvoiceNumber = id;
     using (CustomerManagementSystemContext context = new CustomerManagementSystemContext())
     {
         var invoice = context.Invoices.Where(x => x.InvoiceNumber == id).First();
         this.InvoiceNumber   = invoice.InvoiceNumber;
         this.CreationDate    = invoice.CreationDate;
         this.invoiceComplete = invoice.invoiceComplete;
         this.BusinessNumber  = invoice.BusinessNumber;
         this.BusinessName    = invoice.BusinessName;
         this.BusinessOwner   = invoice.BusinessOwner;
         this.PhoneNumber     = invoice.PhoneNumber;
         this.Email           = invoice.Email;
         this.Website         = invoice.Website;
         this.Logo            = invoice.Logo;
         this.ABN             = invoice.ABN;
         this.CustomerId      = invoice.CustomerId;
         this.CustomerName    = invoice.CustomerName;
         this.CustomerAddress = invoice.CustomerAddress;
         this.CustomerPhone   = invoice.CustomerPhone;
         this.CustomerEmail   = invoice.CustomerEmail;
         this.Notes           = invoice.Notes;
         this.InvoiceItem     = invoice.InvoiceItem.Where(x => x.InvoiceId == InvoiceNumber).ToList();
         this.Tax             = invoice.Tax;
         this.SubTotal        = invoice.SubTotal;
         this.TotalCost       = invoice.TotalCost;
     }
 }
 public List <BusinessAccount> RetrieveBusinessList(string userId)
 {
     using (CustomerManagementSystemContext context = new CustomerManagementSystemContext())
     {
         var businesses = context.BusinessAccounts.Where(x => x.UserAccount == userId).OrderBy(x => x.BusinessName).ToList();
         return(businesses);
     }
 }
 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 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();
     }
 }
예제 #6
0
 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();
     }
 }
예제 #7
0
 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();
     }
 }
예제 #8
0
 public static void AddCustomer(FormCollection collection, int id)
 {
     using (CustomerManagementSystemContext context = new CustomerManagementSystemContext())
     {
         var customer = new Customer(
             BusinessNumber: id,
             CustomerName: collection["CustomerName"],
             CustomerAddress: collection["CustomerAddress"],
             CustomerPhoneNumber: collection["CustomerPhoneNumber"],
             CustomerEmail: collection["CustomerEmail"]
             );
     }
 }
예제 #9
0
        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();
            }
        }
예제 #10
0
        public Customer([Optional] int id)
        {
            this.CustomerId = id;
            using (CustomerManagementSystemContext context = new CustomerManagementSystemContext())
            {
                var customer = context.Customers.Where(x => x.CustomerId == id).First();

                this.BusinessNumber      = customer.BusinessNumber;
                this.CustomerName        = customer.CustomerName;
                this.CustomerAddress     = customer.CustomerAddress;
                this.CustomerPhoneNumber = customer.CustomerPhoneNumber;
                this.CustomerEmail       = customer.CustomerEmail;
            }
        }
예제 #11
0
 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 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 BusinessAccount([Optional] int id)
 {
     this.BusinessNumber = id;
     using (CustomerManagementSystemContext context = new CustomerManagementSystemContext())
     {
         var business = context.BusinessAccounts.Where(x => x.BusinessNumber == id).First();
         this.UserAccount   = business.UserAccount;
         this.BusinessName  = business.BusinessName;
         this.BusinessOwner = business.BusinessOwner;
         this.PhoneNumber   = business.PhoneNumber;
         this.Email         = business.Email;
         this.Website       = business.Website;
         this.Logo          = business.Logo;
         this.ABN           = business.ABN;
         this.Invoices      = business.Invoices.Where(x => x.invoiceComplete == true).ToList();
         this.Customers     = business.Customers.Where(x => x.BusinessNumber == id).ToList();
     }
 }
        public InvoiceDisplay NewInvoiceDisplay(int Id)
        {
            using (CustomerManagementSystemContext context = new CustomerManagementSystemContext())
            {
                var invoice  = new InvoiceDisplay();
                var business = new BusinessAccount(Id);

                invoice.BusinessNumber = business.BusinessNumber;
                invoice.BusinessName   = business.BusinessName;
                invoice.BusinessOwner  = business.BusinessOwner;
                invoice.PhoneNumber    = business.PhoneNumber;
                invoice.Email          = business.Email;
                invoice.Website        = business.Website;
                invoice.Logo           = business.Logo;
                invoice.ABN            = business.ABN;

                //Fill Customers up
                invoice.Customers = context.Customers.Where(x => x.BusinessNumber == Id).ToList();
                return(invoice);
            }
        }
 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();
     }
 }