public async Task <IActionResult> PutCarDetailer(long id, CarDetailerDto carDetailer) { if (id != carDetailer.Id) { return(BadRequest()); } try { _carDetailerService.Update(id, carDetailer); } catch (DbUpdateConcurrencyException) { if (!CarDetailerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public CarDetailerDto Update(long id, CarDetailerDto item) { if (_carDetailerRepository.GetAll().Any(x => x.Phone == item.Phone)) { throw new AppException("Le numéro téléphone " + item.Phone + " existe déjà!"); } return(_carDetailerRepository.Update(id, item)); }
public CarDetailerDto Insert(CarDetailerDto item) { if (string.IsNullOrEmpty(item.Password)) { throw new AppException("Un mot de pass est obligatoire"); } if (_carDetailerRepository.GetAll().Any(x => x.Phone == item.Phone)) { throw new AppException("Le numéro téléphone " + item.Phone + " existe déjà!"); } item.Password = Helper.CreatePasswordHash(item.Password); return(_carDetailerRepository.Insert(item)); }
public IActionResult Register([FromBody] CarDetailerDto carDetailer) { //TODO validation try { _carDetailerService.Insert(carDetailer); return(Ok()); } catch (Exception ex) { //TODO log return(BadRequest(new { message = ex.Message })); } }
public async Task <object> Authenticate([FromBody] CarDetailerDto carDetailerDto) { var carDatiler = _carDetailerService.Authenticate(carDetailerDto.Phone, carDetailerDto.Password); if (carDatiler == null) { return(BadRequest(new { message = "Le numéro de téléphone ou le mot de pass est incorrect" })); } var tokenString = TokenProvider.CreateToken(_appSettings.Secret, carDatiler.Id.ToString() + ",carDetailer"); return(await Task.FromResult(new { Id = carDatiler.Id, Phone = carDatiler.Phone, FirstName = carDatiler.FirstName, LastName = carDatiler.LastName, Token = tokenString })); }