public IActionResult CreateManufacturer([FromBody] CreateManufacturerModel model) { try { if (ModelState.IsValid) { var createResponse = _manufacturerRepository.Create(model.ToEntity()); if (createResponse.StatusCode != 201) { return(StatusCode(createResponse.StatusCode)); } else { return(StatusCode(createResponse.StatusCode, ManufacturerModel.ToModel(createResponse.Data))); } } else { return(BadRequest()); } } catch (Exception e) { return(InternalServerError()); } }
public IActionResult UpdateManufacturer([FromBody] UpdateManufacturerModel model) { try { var getManufacturer = _manufacturerRepository.GetById(model.Id); if (!getManufacturer.isStatusCodeSuccess() || getManufacturer.Data == null) { return(NotFound()); } var updateResponse = _manufacturerRepository.Update(model.ToEntity(getManufacturer.Data)); if (updateResponse.isStatusCodeSuccess() && updateResponse.Data != null) { return(StatusCode(updateResponse.StatusCode, ManufacturerModel.ToModel(updateResponse.Data))); } else { return(StatusCode(updateResponse.StatusCode)); } } catch (Exception e) { return(InternalServerError()); } }
public void ShouldMap_manufacturerToManufacturerModel() { var model = ManufacturerModel.ToModel(_manufacturer); Assert.Equal(1, model.Id); Assert.Equal("Poland", model.Country); Assert.Equal("Cerasit", model.Name); }
public IActionResult GetManufacturer(int id) { try { var manufacturerResponse = _manufacturerRepository.GetById(id); if (!manufacturerResponse.isStatusCodeSuccess()) { return(StatusCode(manufacturerResponse.StatusCode)); } else { return(StatusCode(manufacturerResponse.StatusCode, ManufacturerModel.ToModel(manufacturerResponse.Data))); } } catch (Exception e) { return(InternalServerError()); } }