public async Task <IActionResult> Put(int id, [FromForm] CustomerPostDto dto) { //var entity = _mapper.Map<Customer>(dto); var entity = new Customer() { Id = dto.Id, NameCustomer = dto.NameCustomer, RFC = dto.RFC, PhoneOne = dto.PhoneOne, PhoneTwo = dto.PhoneTwo, Adreess = dto.Adreess, Register = dto.Register, Active = dto.Active, PhotoPath = dto.PhotoPath }; entity.Id = id; string path = ("img/administration/customer"); string pathFull = _baseUrl.GetBaseUrl(path); if (dto.Img != null) { string nameFile = _imgService.SaveFile(dto.Img, pathFull, 600, 600); if (dto.PhotoPath != null) { await _imgService.DeleteFile(pathFull, dto.PhotoPath); } entity.PhotoPath = nameFile; } await _genericRepository.UpdateAsync(entity); return(NoContent()); }
public ActionResult <Customer> CreateCustomer(CustomerPostDto customerCreateDto) { var customerModel = _mapper.Map <Customer>(customerCreateDto); _repository.CreateCustomer(customerModel); _repository.SaveChanges(); return(CreatedAtRoute("GetCommandById", new { Id = customerModel.Id }, customerModel)); }
public CustomerDto AddCustomer(CustomerPostDto customer) { var exitingCustomer = _unityOfWork.Customers.GetCustomerByEmail(customer.ContactEmail); if (exitingCustomer != null) { throw new ValidationException($"customer with email: {exitingCustomer.ContactEmail} already exists"); } var newCustomer = _mapper.Map <Customer>(customer); _unityOfWork.Customers.Add(newCustomer); _unityOfWork.Complete(); return(GetCustomer(customer.ContactEmail)); }
public async Task <ActionResult <Customer> > Post([FromBody] CustomerPostDto dto) { var entity = _mapper.Map <Customer>(dto); try { string path = ("img/administration/customer"); string pathFull = _baseUrl.GetBaseUrl(path); if (dto.Img != null) { string nameFile = _imgService.SaveFile(dto.Img, pathFull, 600, 600); entity.PhotoPath = nameFile; } var result = await _genericRepository.CreateAsync(entity); return(new CreatedAtRouteResult("GetCustomer", new { id = result.Id }, result)); } catch (Exception e) { return(NotFound(e)); } }
public void Post([FromBody] CustomerPostDto customer) { _customerService.AddCustomer(customer); }