public ActionResult CreateNewProduct(CreateProductDTO createProductDTO)
        {
            var product = _mapper.Map <Product>(createProductDTO);

            _ProductService.AddProduct(product);
            return(Ok());
        }
        /// <summary>
        /// this method adds the product to the database
        /// throws an exception on failure
        /// </summary>
        /// <param name="model">product model</param>
        public async Task <ReadProductDTO> AddAsync(CreateProductDTO model)
        {
            var prod = _mapper.Map <Product>(model);

            prod.PhotoPath = await _fileManager.SaveImage(model.Photo);

            await _productRepository.AddAsync(prod);

            await _productRepository.SaveAsync();

            prod = await _productRepository.GetByIdWithDetailsAsync(prod.Id);

            prod.ProductCategories = new List <ProductCategory>();

            var categories = _categoryRepository.FindAll();

            foreach (var item in model.CategoriesIds.Distinct())
            {
                if (!categories.Contains(categories.FirstOrDefault(x => x.Id == item)))
                {
                    throw new AuctionException("one of categories does not exist", System.Net.HttpStatusCode.BadRequest);
                }
                prod.ProductCategories.Add(new ProductCategory {
                    ProductId = prod.Id, CategoryId = item
                });
            }

            _productRepository.Update(prod);

            await _productRepository.SaveAsync();

            return(_mapper.Map <ReadProductDTO>(prod));
        }
示例#3
0
        public async Task <ActionResult> PostMerchant(CreateProductDTO product)
        {
            var id = await productsService.PostProduct(mapper.Map <Product>(product));


            return(CreatedAtAction("GetProduct", new { id = id }, id));
        }
示例#4
0
        public async Task <ActionResult <Product> > PostProduct(CreateProductDTO productDTO)
        {
            Product product = new Product(productDTO.Manufacturer, productDTO.Model, productDTO.Price, productDTO.StashQuantity);

            _context.Product.Add(product);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProduct", new { id = product.Id }, product));
        }
示例#5
0
        public async Task <ProductDTO> CreateAsync(CreateProductDTO createProductDTO)
        {
            var product = _mapper.Map <Product>(createProductDTO);

            await _context.AddAsync(product);

            await _context.SaveChangesAsync();

            return(_mapper.Map <ProductDTO>(product));
        }
        public async Task <int> Create(CreateProductDTO newProduct)
        {
            var response = await _httpService.Post <CreateProductDTO, int>(baseURL, newProduct);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }

            return(response.Data);
        }
 public static Products AsModel(this CreateProductDTO product)
 {
     return(new Products
     {
         BrandID = product.BrandID,
         Name = product.Name,
         Description = product.Description,
         SubCategoryID = product.SubCategoryID,
         CategoryID = product.CategoryID
     });
 }
示例#8
0
        public async Task <ProductDTO> Add(CreateProductDTO productDTO)
        {
            if (productDTO == null)
            {
                return(null);
            }
            var p       = ProductConverter.Convert(productDTO);
            var product = await unitOfWork.Repository <Product>().Add(p);

            return(ProductConverter.Convert(product));
        }
        public async Task <ActionResult <int> > Add(CreateProductDTO newProduct)
        {
            var product = _mapper.Map <Product>(newProduct);

            product.CategoryId = await _categoryRepository.CreateIfNotExists(newProduct.CategoryName);

            _context.Product.Add(product);
            await _context.SaveChangesAsync();

            return(Ok(product.Id));
        }
示例#10
0
 public async Task UpdateProductAsync(CreateProductDTO product)
 {
     if (Get(product.Id) == null)
     {
         throw new Exception("Taki produkt nie istnieje");
     }
     else
     {
         Shop.Core.Domain.Product model = new Shop.Core.Domain.Product(product.Id, product.Name, product.Description, product.Price, product.Quantity, product.CategoryId);
         await productRepository.UpdateProductAsync(model);
     }
 }
示例#11
0
        public async Task <IActionResult> Add(CreateProductDTO createDto)
        {
            var productDto = await service.Add(createDto);

            if (productDto != null)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest($"{nameof(productDto)} is null"));
            }
        }
示例#12
0
        public static Product Convert(CreateProductDTO product)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            return(new Product
            {
                Title = product.Title,
                CategoryId = product.CategoryId,
                //Category= CategoryConverter.Convert(product.CategoryDTO)
            });
        }
示例#13
0
        public async Task AddProduct(CreateProductDTO product)
        {
            var item = await Get(product.Id);

            if (item != null)
            {
                throw new Exception("Taki produkt już istnieje");
            }
            else
            {
                Shop.Core.Domain.Product model = new Shop.Core.Domain.Product(product.Id, product.Name, product.Description, product.Price, product.Quantity, product.CategoryId);
                await productRepository.AddProduct(model);
            }
        }
        public async Task <ActionResult <CreateProductDTO> > PostProduct(CreateProduct createProduct)
        {
            CreateProduct createProductModel = createProduct;

            if (!this.ValidTokenAdmin(createProductModel.AccessToken))
            {
                return(BadRequest(this.GetError(Error.INVALID_TOKEN)));
            }


            if (createProductModel.Name == null || createProductModel.Name.Length == 0)
            {
                return(BadRequest(this.GetError(Error.MISSING_NAME)));
            }
            if (createProductModel.Type == null || createProductModel.Type.Length == 0)
            {
                return(BadRequest(this.GetError(Error.MISSING_TYPE)));
            }
            if (createProductModel.Description == null || createProductModel.Description.Length == 0)
            {
                return(BadRequest(this.GetError(Error.MISSING_DESCRIPTION)));
            }
            if (createProductModel.ImagePath == null || createProductModel.ImagePath.Length == 0)
            {
                return(BadRequest(this.GetError(Error.MISSING_IMAGE_PATH)));
            }
            if (createProductModel.Status == null || createProductModel.Status.Length == 0)
            {
                return(BadRequest(this.GetError(Error.MISSING_STATUS)));
            }

            Product product = new Product();

            product.ProductId   = Guid.NewGuid().ToString();
            product.Name        = createProductModel.Name;
            product.Type        = createProductModel.Type;
            product.Description = createProductModel.Description;
            product.ImagePath   = createProductModel.ImagePath;
            product.Status      = createProductModel.Status;
            product.Price       = Convert.ToDecimal(createProductModel.Price);

            _context.Products.Add(product);
            await _context.SaveChangesAsync();

            CreateProductDTO productDTO = new CreateProductDTO(product);

            return(CreatedAtAction(nameof(GetProduct), new { id = product.ProductId }, productDTO));
        }
示例#15
0
        public async Task <ProductDTO> CreateProduct(CreateProductDTO product)
        {
            if (product.Name.Length < 3)
            {
                throw new Exception("Product Name should be atleast 3 characters long.");
            }
            if (product.Description.Length < 5)
            {
                throw new Exception("Product Description should be atleast 5 characters long.");
            }
            var p = product.AsModel();
            await _context.Products.AddAsync(p);

            await _context.SaveChangesAsync();

            return(p.AsDTO());
        }
示例#16
0
        public CreateProductDTO CreateProduct([FromBody] ProductCreateRequest productCreateRequest)
        {
            var product      = _productService.CreateProduct(productCreateRequest);
            var responseJson = new CreateProductDTO();

            if (product.HasValidationErrors() || product.HasDBErrors())
            {
                responseJson.validationErrors = _convertErrorsToString(product.ValidationErrors);
                responseJson.dbErrors         = product.DBErrors;
                responseJson.status           = Status.Failed;
            }
            else
            {
                responseJson.createResponse = product;
                responseJson.status         = Status.Success;
            }
            return(responseJson);
        }
示例#17
0
        public static Product Convert(CreateProductDTO product)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            return(new Product
            {
                Title = product.Title,
                BrandId = product.BrandId,

                CategoryId = product.CategoryId,
                Description = product.Description,
                Price = product.Price,
                Quantity = product.Quantity,
                IsDeleted = false
            });
        }
示例#18
0
        public async Task <IActionResult> CreateProduct(CreateProductDTO product)
        {
            try
            {
                var p = await _adminservice.CreateProduct(product);

                return(StatusCode(201, p));
            }
            catch (Exception e)
            {
                if (e.Message.Length > 0)
                {
                    return(BadRequest(e.Message));
                }
                else
                {
                    throw;
                }
            }
        }
 public Task Update(CreateProductDTO newProduct)
 {
     throw new NotImplementedException();
 }
示例#20
0
        public bool EditProduct(CreateProductDTO product)
        {
            bool isAdded = false;

            isAdded = DataProvider.EditProduct(product);

            string path = @"imgs\" + product.Group + @"\" + product.Id;

            Directory.Delete(path, true);
            Directory.CreateDirectory(path);
            if (product.Img1?.Length > 0)
            {
                using (var ms = new MemoryStream())
                {
                    product.Img1.CopyTo(ms);
                    var    fileBytes = ms.ToArray();
                    string s         = Convert.ToBase64String(fileBytes);
                    // act on the Base64 data
                    ISupportedImageFormat format = new JpegFormat {
                        Quality = 75
                    };
                    using (MemoryStream inStream = new MemoryStream(fileBytes))
                        using (MemoryStream outStream = new MemoryStream())
                        {
                            using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
                            {
                                var maxSize = new Size(400, 0);
                                var r       = new ResizeLayer(maxSize);
                                r.MaxSize = maxSize;
                                imageFactory.Load(inStream)
                                .BackgroundColor(Color.White)
                                .Resize(r)
                                .Format(format)
                                .Save(outStream);
                            }

                            using (System.Drawing.Image image = System.Drawing.Image.FromStream(outStream))
                            {
                                var filePath = path + @"\1.jpg";
                                image.Save(filePath, ImageFormat.Jpeg);
                            }
                        }
                }
            }
            if (product.Img2?.Length > 0)
            {
                using (var ms = new MemoryStream())
                {
                    product.Img2.CopyTo(ms);
                    var    fileBytes = ms.ToArray();
                    string s         = Convert.ToBase64String(fileBytes);
                    // act on the Base64 data
                    ISupportedImageFormat format = new JpegFormat {
                        Quality = 75
                    };
                    using (MemoryStream inStream = new MemoryStream(fileBytes))
                        using (MemoryStream outStream = new MemoryStream())
                        {
                            using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
                            {
                                var maxSize = new Size(400, 0);
                                var r       = new ResizeLayer(maxSize);
                                r.MaxSize = maxSize;
                                imageFactory.Load(inStream)
                                .BackgroundColor(Color.White)
                                .Resize(r)
                                .Format(format)
                                .Save(outStream);
                            }

                            using (System.Drawing.Image image = System.Drawing.Image.FromStream(outStream))
                            {
                                var filePath = path + @"\2.jpg";
                                image.Save(filePath, ImageFormat.Jpeg);
                            }
                        }
                }
            }
            if (product.Img3?.Length > 0)
            {
                using (var ms = new MemoryStream())
                {
                    product.Img3.CopyTo(ms);
                    var    fileBytes = ms.ToArray();
                    string s         = Convert.ToBase64String(fileBytes);
                    // act on the Base64 data
                    ISupportedImageFormat format = new JpegFormat {
                        Quality = 75
                    };
                    using (MemoryStream inStream = new MemoryStream(fileBytes))
                        using (MemoryStream outStream = new MemoryStream())
                        {
                            using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
                            {
                                var maxSize = new Size(400, 0);
                                var r       = new ResizeLayer(maxSize);
                                r.MaxSize = maxSize;
                                imageFactory.Load(inStream)
                                .BackgroundColor(Color.White)
                                .Resize(r)
                                .Format(format)
                                .Save(outStream);
                            }

                            using (System.Drawing.Image image = System.Drawing.Image.FromStream(outStream))
                            {
                                var filePath = path + @"\3.jpg";
                                image.Save(filePath, ImageFormat.Jpeg);
                            }
                        }
                }
            }

            return(isAdded);
        }
示例#21
0
        public static bool EditProduct(CreateProductDTO order)
        {
            //List<ProductDTO> ProductsList = new List<ProductDTO>();
            using (SqlConnection conn = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("sp_update_product", conn);

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", order.Id);
                cmd.Parameters.AddWithValue("@name", order.Name);
                cmd.Parameters.AddWithValue("@desc", order.Description);
                cmd.Parameters.AddWithValue("@price", order.Price);
                cmd.Parameters.AddWithValue("@group", order.Group);
                cmd.Parameters.AddWithValue("@type", order.Type);
                cmd.Parameters.AddWithValue("@sub_type", order.SubType);
                cmd.Parameters.AddWithValue("@discount", order.Discount);

                cmd.Parameters.AddWithValue("@cat_manufacturer", order.Cat_manufacturer);
                cmd.Parameters.AddWithValue("@cat_color_palette", order.Cat_color_palette);
                cmd.Parameters.AddWithValue("@cat_appearance", order.Cat_appearance);
                cmd.Parameters.AddWithValue("@cat_washable", order.Cat_washable);
                cmd.Parameters.AddWithValue("@cat_smell", order.Cat_smell);
                cmd.Parameters.AddWithValue("@cat_color", order.Cat_color);
                cmd.Parameters.AddWithValue("@cat_room_type", order.Cat_room_type);
                cmd.Parameters.AddWithValue("@cat_appointment", order.Cat_appointment);
                cmd.Parameters.AddWithValue("@cat_type", order.Cat_type);
                cmd.Parameters.AddWithValue("@cat_stencil_theme", order.Cat_stencil_theme);
                cmd.Parameters.AddWithValue("@cat_place_of_use", order.Cat_place_of_use);
                cmd.Parameters.AddWithValue("@cat_created_for", order.Cat_created_for);
                cmd.Parameters.AddWithValue("@cat_finish_guarantee", order.Cat_finish_guarantee);
                cmd.Parameters.AddWithValue("@cat_effect", order.Cat_effect);
                cmd.Parameters.AddWithValue("@cat_volume", order.Cat_volume);
                cmd.Parameters.AddWithValue("@cat_duration_of_protection", order.Cat_duration_of_protection);
                cmd.Parameters.AddWithValue("@cat_surface_of_application", order.Cat_surface_of_application);
                cmd.Parameters.AddWithValue("@cat_type_of_use", order.Cat_type_of_use);
                cmd.Parameters.AddWithValue("@cat_brush_type", order.Cat_brush_type);
                cmd.Parameters.AddWithValue("@cat_width", order.Cat_width);
                cmd.Parameters.AddWithValue("@cat_fiber_material", order.Cat_fiber_material);
                cmd.Parameters.AddWithValue("@cat_structure", order.Cat_structure);
                cmd.Parameters.AddWithValue("@cat_resistant", order.Cat_resistant);
                cmd.Parameters.AddWithValue("@cat_gluing_strength", order.Cat_gluing_strength);
                cmd.Parameters.AddWithValue("@cat_capture_time", order.Cat_capture_time);
                cmd.Parameters.AddWithValue("@cat_gluing_material", order.Cat_gluing_material);
                cmd.Parameters.AddWithValue("@cat_frost_resistance", order.Cat_frost_resistance);
                cmd.Parameters.AddWithValue("@cat_heat_resistance", order.Cat_heat_resistance);
                cmd.Parameters.AddWithValue("@cat_color_after_drying", order.Cat_color_after_drying);
                cmd.Parameters.AddWithValue("@cat_external_material", order.Cat_external_material);
                cmd.Parameters.AddWithValue("@cat_application_type", order.Cat_application_type);
                cmd.Parameters.AddWithValue("@cat_paint_type", order.Cat_paint_type);
                cmd.Parameters.AddWithValue("@cat_consumption", order.Cat_consumption);
                cmd.Parameters.AddWithValue("@cat_application_temperature", order.Cat_application_temperature);


                conn.Open();
                //dt.Load(cmd.ExecuteReader());
                cmd.ExecuteNonQuery();


                return(true);
            }
        }
示例#22
0
        public static bool AddProduct(CreateProductDTO order, out int id)
        {
            int cnt = 0;

            if (order.Img1 != null)
            {
                cnt++;
            }
            if (order.Img2 != null)
            {
                cnt++;
            }
            if (order.Img3 != null)
            {
                cnt++;
            }
            //DataTable dt = new DataTable();

            //List<ProductDTO> ProductsList = new List<ProductDTO>();
            using (SqlConnection conn = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("sp_insert_product", conn);

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@name", order.Name);
                cmd.Parameters.AddWithValue("@desc", order.Description);
                cmd.Parameters.AddWithValue("@price", order.Price);
                cmd.Parameters.AddWithValue("@group", order.Group);
                cmd.Parameters.AddWithValue("@type", order.Type);
                cmd.Parameters.AddWithValue("@sub_type", order.SubType);
                cmd.Parameters.AddWithValue("@discount", order.Discount);
                cmd.Parameters.AddWithValue("@imgscount", cnt);


                cmd.Parameters.AddWithValue("@cat_manufacturer", order.Cat_manufacturer);
                cmd.Parameters.AddWithValue("@cat_color_palette", order.Cat_color_palette);
                cmd.Parameters.AddWithValue("@cat_appearance", order.Cat_appearance);
                cmd.Parameters.AddWithValue("@cat_washable", order.Cat_washable);
                cmd.Parameters.AddWithValue("@cat_smell", order.Cat_smell);
                cmd.Parameters.AddWithValue("@cat_color", order.Cat_color);
                cmd.Parameters.AddWithValue("@cat_room_type", order.Cat_room_type);
                cmd.Parameters.AddWithValue("@cat_appointment", order.Cat_appointment);
                cmd.Parameters.AddWithValue("@cat_type", order.Cat_type);
                cmd.Parameters.AddWithValue("@cat_stencil_theme", order.Cat_stencil_theme);
                cmd.Parameters.AddWithValue("@cat_place_of_use", order.Cat_place_of_use);
                cmd.Parameters.AddWithValue("@cat_created_for", order.Cat_created_for);
                cmd.Parameters.AddWithValue("@cat_finish_guarantee", order.Cat_finish_guarantee);
                cmd.Parameters.AddWithValue("@cat_effect", order.Cat_effect);
                cmd.Parameters.AddWithValue("@cat_volume", order.Cat_volume);
                cmd.Parameters.AddWithValue("@cat_duration_of_protection", order.Cat_duration_of_protection);
                cmd.Parameters.AddWithValue("@cat_surface_of_application", order.Cat_surface_of_application);
                cmd.Parameters.AddWithValue("@cat_type_of_use", order.Cat_type_of_use);
                cmd.Parameters.AddWithValue("@cat_brush_type", order.Cat_brush_type);
                cmd.Parameters.AddWithValue("@cat_width", order.Cat_width);
                cmd.Parameters.AddWithValue("@cat_fiber_material", order.Cat_fiber_material);
                cmd.Parameters.AddWithValue("@cat_structure", order.Cat_structure);
                cmd.Parameters.AddWithValue("@cat_resistant", order.Cat_resistant);
                cmd.Parameters.AddWithValue("@cat_gluing_strength", order.Cat_gluing_strength);
                cmd.Parameters.AddWithValue("@cat_capture_time", order.Cat_capture_time);
                cmd.Parameters.AddWithValue("@cat_gluing_material", order.Cat_gluing_material);
                cmd.Parameters.AddWithValue("@cat_frost_resistance", order.Cat_frost_resistance);
                cmd.Parameters.AddWithValue("@cat_heat_resistance", order.Cat_heat_resistance);
                cmd.Parameters.AddWithValue("@cat_color_after_drying", order.Cat_color_after_drying);
                cmd.Parameters.AddWithValue("@cat_external_material", order.Cat_external_material);
                cmd.Parameters.AddWithValue("@cat_application_type", order.Cat_application_type);
                cmd.Parameters.AddWithValue("@cat_paint_type", order.Cat_paint_type);
                cmd.Parameters.AddWithValue("@cat_consumption", order.Cat_consumption);
                cmd.Parameters.AddWithValue("@cat_application_temperature", order.Cat_application_temperature);


                //cmd.Parameters.Add("@items", SqlDbType.Structured);
                //cmd.Parameters.Add("@items", SqlDbType.Structured);
                //cmd.Parameters.Add("@items", SqlDbType.Structured);
                SqlParameter outParameter = new SqlParameter("@id", SqlDbType.Int);
                outParameter.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(outParameter);

                //cmd.Parameters["@items"].Value = order.Items;
                //cmd.Parameters.AddWithValue("@items", order.Items);


                conn.Open();
                //dt.Load(cmd.ExecuteReader());
                cmd.ExecuteNonQuery();
                id = Convert.ToInt32(outParameter.Value);
                //foreach (DataRow dr in dt.Rows)
                //{
                //	ProductsList.Add(dr.ConvertToProductDTO());
                //}



                return(true);
            }
        }
 public async Task <IActionResult> CreateProduct([FromForm] CreateProductDTO product)
 {
     product.UserId = _userManager.GetUserId(User);
     return(Ok(await _productService.AddAsync(product)));
 }
示例#24
0
        public async Task <ActionResult> CreateProduct([FromForm] CreateProductDTO createProductDTO)
        {
            var productDTO = await _productService.CreateAsync(createProductDTO);

            return(Ok(productDTO));
        }