public async Task Create(ProductWriteModel productModel) { HttpClient httpClient = this.CreateHttpClient(); StringContent content = new StringContent(JsonConvert.SerializeObject(productModel), Encoding.UTF8, "application/json"); HttpResponseMessage response = await httpClient.PostAsync("/api/product", content); response.EnsureSuccessStatusCode(); }
private static ProductDto MapToDto( ProductWriteModel input, long?id = null, string createdBy = null, string modifiedBy = null) => new ProductDto { Id = id, CreatedBy = createdBy, ModifiedBy = modifiedBy, Brand = input.Brand, Type = input.Type };
public async Task <IActionResult> CreateProduct([FromBody] ProductWriteModel product) { if (ModelState.IsValid) { var createdProduct = await this.productsService.Create(product); return(Json(createdProduct)); } return(Json(false)); }
private bool AlreadyExists(ProductWriteModel model) { // All 3 properties are required. var query = new ProductQuery { Brand = model.Brand, Type = model.Type, Group = model.Group }; return(_repo.Query(query).Any()); }
public IHttpActionResult Post(ProductWriteModel model) { if (model == null) { return(BadRequest(Constants.MISSING_MESSAGE_BODY)); } var dto = MapToDto(model, createdBy: _shibbolethAttribs.GetUid()); long id = _repo.Insert(dto); // Refetch the data. dto = _repo.GetById(id); var readModel = MapToModel(dto); return(CreatedAtRoute("GetProductById", new { id = readModel.Id }, readModel)); }
public async Task <ProductWriteModel> Create(ProductWriteModel product) { var user = await this.userRepository.GetByName(UserInfo.UserName); var company = companiesRepository.GetBydId(user.Id); productsRepository.Add(new Product { CompanyID = company.Id, Description = product.Description, Name = product.Name, Url = product.Url }); //TODO: get product with the ID and return it. return(product); }
public IHttpActionResult Post(ProductWriteModel model) { if (model == null) { return(BadRequest(Constants.MISSING_MESSAGE_BODY)); } if (AlreadyExists(model)) { return(BadRequest("Product with the specified Brand, Type and Group already exists.")); } var dto = MapToDto(model, createdBy: _jwt.UserId); long id = _repo.Insert(dto); // Refetch the data. dto = _repo.GetById(id); var readModel = MapToModel(dto); return(CreatedAtRoute(nameof(GetProductById), new { id = readModel.Id }, readModel)); }
public IHttpActionResult Put(long id, ProductWriteModel model) { if (model == null) { return(BadRequest(Constants.MISSING_MESSAGE_BODY)); } if (!_repo.Exists(id)) { return(NotFound()); } var dto = MapToDto(model, id, modifiedBy: _jwt.UserId); _repo.Update(dto); // Refetch the data. dto = _repo.GetById(id); var readModel = MapToModel(dto); return(Ok(readModel)); }
public async Task Create(ProductWriteModel product) { await this.writeApiClient.Create(product); }
public async Task <ProductWriteModel> Update(ProductWriteModel product) { throw new System.NotImplementedException(); }