Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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 }));
            }
        }
Ejemplo n.º 5
0
        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
            }));
        }