public ActionResult Create(ConsigneeModel consigneeModel)
        {
            if (ModelState.IsValid)
            {
                using (var necessitiesContext = new NecessitiesContext())
                {
                    necessitiesContext.Consignees.Add(
                        new Consignee
                            {
                                ConsigneeId = consigneeModel.ConsigneeId,
                                FirstName = consigneeModel.FirstName,
                                LastName = consigneeModel.LastName,
                                AddressOne = consigneeModel.AddressOne,
                                AddressTwo = consigneeModel.AddressTwo,
                                City = consigneeModel.City,
                                State = consigneeModel.State,
                                PostalCode = consigneeModel.PostalCode,
                                PhoneNumber = GetCleanPhoneNumber(consigneeModel.PhoneNumber),
                                Email = consigneeModel.Email,
                                Percentage = consigneeModel.Percentage/100,
                                CreationDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            });

                    necessitiesContext.SaveChanges();
                }

                return RedirectToAction("Index");
            }

            return View(consigneeModel);
        }
        public ActionResult Edit(ItemTypeModel itemTypeModel)
        {
            using (var necessitiesContext = new NecessitiesContext())
            {
                var itemType = necessitiesContext.ItemTypes.First(x => x.ItemTypeId == itemTypeModel.ItemTypeId);

                itemType.Description = itemTypeModel.Description;
                itemType.Active = itemTypeModel.Active;

                necessitiesContext.SaveChanges();
            }

            return RedirectToAction("Index");
        }
        public ActionResult Create(DateTime startDate, decimal taxRate)
        {
            var salesTaxRateModel = new SalesTaxRateModel { StartDate = startDate, TaxRate = taxRate / 100 };
            using (var necessitiesContext = new NecessitiesContext())
            {
                necessitiesContext.SalesTaxRates.Add(new SalesTaxRate
                {
                    StartDate = salesTaxRateModel.StartDate,
                    TaxRate = salesTaxRateModel.TaxRate
                });

                necessitiesContext.SaveChanges();
            }

            return RedirectToAction("Index");
        }
        public ActionResult Create(ItemTypeModel itemTypeModel)
        {
            using (var necessitiesContext = new NecessitiesContext())
            {
                necessitiesContext.ItemTypes.Add(
                    new ItemType
                        {
                            Description = itemTypeModel.Description,
                            Active = true
                        });

                necessitiesContext.SaveChanges();
            }

            return RedirectToAction("Index");
        }
        public ActionResult Create(SaleModel saleModel)
        {
            if (ModelState.IsValid)
            {
                using (var necessitiesContext = new NecessitiesContext())
                {
                    necessitiesContext.Sales.Add(
                        new Sale
                            {
                                SaleId = saleModel.SaleId,
                                Date = saleModel.Date,
                                TaxRate = saleModel.TaxRate,
                                CreationDate = DateTime.Now,
                                UpdatedDate = DateTime.Now,
                                SaleItems =
                                    saleModel.SaleItems.Select(
                                        item => new SaleItem
                                            {
                                                SaleItemId = item.SaleItemId,
                                                Amount = item.Amount,
                                                Description = item.Description,
                                                ItemTypeId = item.ItemTypeId,
                                                ConsigneeId = item.ConsigneeId,
                                                SaleId = item.SaleId,
                                                CreationDate = item.CreationDate,
                                                UpdatedDate = item.UpdatedDate
                                            }).ToList()
                            });

                    necessitiesContext.SaveChanges();
                }

                return RedirectToAction("Index");
            }

            return View(saleModel);
        }
        public ActionResult Edit(ConsigneeModel consigneeModel)
        {
            if (ModelState.IsValid)
            {
                using (var necessitiesContext = new NecessitiesContext())
                {
                    var consignee = necessitiesContext.Consignees.First(x => x.ConsigneeId == consigneeModel.ConsigneeId);

                    consignee.ConsigneeId = consigneeModel.ConsigneeId;
                    consignee.FirstName = consigneeModel.FirstName;
                    consignee.LastName = consigneeModel.LastName;
                    consignee.AddressOne = consigneeModel.AddressOne;
                    consignee.AddressTwo = consigneeModel.AddressTwo;
                    consignee.City = consigneeModel.City;
                    consignee.State = consigneeModel.State;
                    consignee.PostalCode = consigneeModel.PostalCode;
                    consignee.PhoneNumber = GetCleanPhoneNumber(consigneeModel.PhoneNumber);
                    consignee.Email = consigneeModel.Email;
                    consignee.Percentage = consigneeModel.Percentage / 100;
                    consignee.UpdatedDate = DateTime.Now;

                    necessitiesContext.SaveChanges();
                }

                return RedirectToAction("Index");
            }

            return View(consigneeModel);
        }