Exemplo n.º 1
0
        public ActionResult Edit(int consigneeId)
        {
            ConsigneeModel consigneeModel;
            using (var necessitiesContext = new NecessitiesContext())
            {
                var consignee = necessitiesContext.Consignees.First(x => x.ConsigneeId == consigneeId);

                consigneeModel = new ConsigneeModel
                                     {
                                         AddressOne = consignee.AddressOne,
                                         AddressTwo = consignee.AddressTwo,
                                         City = consignee.City,
                                         ConsigneeId = consignee.ConsigneeId,
                                         CreationDate = consignee.CreationDate,
                                         Email = consignee.Email,
                                         FirstName = consignee.FirstName,
                                         LastName = consignee.LastName,
                                         Percentage = consignee.Percentage * 100,
                                         PhoneNumber = consignee.PhoneNumber,
                                         PostalCode = consignee.PostalCode,
                                         State = consignee.State,
                                         UpdatedDate = consignee.UpdatedDate
                                     };
            }

            return View(consigneeModel);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }