Ejemplo n.º 1
0
        public async Task <IActionResult> EditPersonalData(EditLoggedInCustomerViewModel customer)
        {
            if (!ModelState.IsValid)
            {
                return(View(customer));
            }

            string email = User.Identity.Name;

            var customerLoggedin = await _context.Customer.SingleOrDefaultAsync(c => c.Email == email);

            if (customerLoggedin == null)
            {
                return(NotFound());
            }

            customerLoggedin.Name = customer.Name;

            try
            {
                _context.Update(customerLoggedin);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //todo: show error message

                throw;
            }
            return(RedirectToAction(nameof(Index), "Home"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditPersonalData()
        {
            string email = User.Identity.Name;

            var customer = await _context.Customer.SingleOrDefaultAsync(c => c.Email == email);

            if (customer == null)
            {
                return(NotFound());
            }

            EditLoggedInCustomerViewModel customerInfo = new EditLoggedInCustomerViewModel
            {
                Name  = customer.Name,
                Email = customer.Email
            };

            return(View(customerInfo));
        }