Esempio n. 1
0
        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();
        }
Esempio n. 2
0
 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
 };
Esempio n. 3
0
        public async Task <IActionResult> CreateProduct([FromBody] ProductWriteModel product)
        {
            if (ModelState.IsValid)
            {
                var createdProduct = await this.productsService.Create(product);

                return(Json(createdProduct));
            }

            return(Json(false));
        }
Esempio n. 4
0
        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());
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
 public async Task Create(ProductWriteModel product)
 {
     await this.writeApiClient.Create(product);
 }
Esempio n. 10
0
 public async Task <ProductWriteModel> Update(ProductWriteModel product)
 {
     throw new System.NotImplementedException();
 }