Exemple #1
0
        public IActionResult Edit(CustomerEditDeleteModel model)
        {
            if (this.ModelState.IsValid)
            {
                this.customerService.UpdateCustomer(model);

                return(RedirectToAction("All", new { order = "ascending" }));
            }

            return(View(model));
        }
Exemple #2
0
        public IActionResult Edit(int?id)
        {
            if (id is null)
            {
                return(NotFound());
            }

            CustomerEditDeleteModel model = this.customerService.GetUserEditDeleteModelById(id);

            return(View(model));
        }
Exemple #3
0
        public void UpdateCustomer(CustomerEditDeleteModel model)
        {
            if (!this.db.Customers.Any(c => c.Id == model.Id))
            {
                return;
            }

            var customer = this.db.Customers.FirstOrDefault(c => c.Id == model.Id);

            bool isYoungDriver = (DateTime.Now - model.Birthday).Value.Days < (365 * 2);

            customer.Name          = model.Name;
            customer.Birthday      = model.Birthday;
            customer.IsYoungDriver = isYoungDriver;
            this.db.SaveChanges();
        }