public async Task <ActionResult> Excute() { var _context = new TGDDContext(); Customer customer = await _context.Customers.FindAsync(CustomerId); customer.Password = SecurityUtils.CreateMD5(NewPassword); //OldPassword = SecurityUtils.CreateMD5(OldPassword); //if(OldPassword == customer.Password) //{ // customer.Password = SecurityUtils.CreateMD5(NewPassword); //} //else //{ // return BadRequest("Mật khẩu hiện tại không đúng !"); //} _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch { throw; }; return(Ok("Đổi mật khẩu thành công !")); }
public async Task <ActionResult <Customer> > Excute() { var _context = new TGDDContext(); var newCustomerId = _context.Customers.Max(c => c.Id) + 1; Customer.Id = newCustomerId; Customer.Password = SecurityUtils.CreateMD5(Customer.Password); _context.Customers.Add(Customer); try { await _context.SaveChangesAsync(); { MailClass mailClass = GetMailObject(Customer); await _mailService.SendMail(mailClass); } } catch (DbUpdateException) { bool customerExist = _context.Customers.Any(c => c.Id == Customer.Id); if (customerExist) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetCustomers", new { id = Customer.Id }, Customer)); }
public async Task <ActionResult <Customer> > Excute() { var _context = new TGDDContext(); Customer customer = _context.Customers.FirstOrDefault(customer => customer.UserName == Username); if (customer == null) { return(BadRequest()); } else { customer.Password = SecurityUtils.CreateMD5(Password); _context.Entry(customer).State = EntityState.Modified; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { bool customerExist = _context.Customers.Any(c => c.Id == customer.Id); if (!customerExist) { return(NotFound()); } else { throw; } } return(Ok()); }