示例#1
0
        public async Task GetProductDetails_Success()
        {
            //Setup
            var          productId = Guid.NewGuid();
            ProductModel data      = new ProductModel()
            {
                Id = productId
            };
            ProductViewModel resultProduct = new ProductViewModel()
            {
                Id = productId
            };
            ProductInputViewModel productInputViewModel = new ProductInputViewModel()
            {
                Id = productId
            };
            ProductInputModel productInputModel = new ProductInputModel()
            {
                Id = productId
            };

            mapper.Setup(m => m.Map <ProductInputModel>(productInputViewModel)).Returns(productInputModel);
            mapper.Setup(m => m.Map <ProductViewModel>(data)).Returns(resultProduct);
            productsBA.Setup(repo => repo.GetProductIncreaseViewcount(productInputModel)).Returns(Task.FromResult(data));

            //Action
            var controller = new ProductController(logger.Object, productsBA.Object, mapper.Object);
            var result     = await controller.GetProductDetails(productInputViewModel);

            //Assert
            var okObjectResult = result.Result as OkObjectResult;
            var product        = okObjectResult.Value as ProductViewModel;

            Assert.AreEqual(product.Id, productId);
        }
示例#2
0
        public IActionResult Add(string id)
        {
            var model = new ProductInputViewModel
            {
                OrderId = id
            };

            return(this.View("Add", model));
        }
示例#3
0
        public async Task GetProductDetails_Input_Null()
        {
            //Setup
            ProductInputViewModel productInputViewModel = null;

            //Action
            var controller = new ProductController(logger.Object, productsBA.Object, mapper.Object);
            var result     = await controller.GetProductDetails(productInputViewModel);
        }
示例#4
0
        public IActionResult Add()
        {
            var model = new ProductInputViewModel()
            {
                AvailableCategories = this.categoriesService.All().ToList(),
                AvailableAllergens  = this.allergensService.All().ToList(),
                AvailablePackages   = this.packagesService.All().ToList(),
            };

            return(this.View(model));
        }
示例#5
0
        public async Task AddAsync(ProductInputViewModel model)
        {
            var product = new MenuProduct()
            {
                Name        = model.Name,
                CategoryId  = model.CategoryId,
                Description = model.Description,
                HasExtras   = model.HasExtras,
                Sizes       = new List <ProductSize>()
                {
                },
            };

            foreach (var item in model.Allergens)
            {
                product.Allergens.Add(new AllergensProducts()
                {
                    ProductId  = product.Id,
                    AllergenId = item,
                });
            }

            foreach (var size in model.Sizes)
            {
                if (string.IsNullOrEmpty(size.SizeName))
                {
                    continue;
                }

                product.Sizes.Add(
                    new ProductSize()
                {
                    SizeName             = size.SizeName,
                    PackageId            = size.PackageId,
                    Price                = size.Price,
                    Weight               = size.Weight,
                    MaxProductsInPackage = size.MaxProductsInPackage,
                    MenuProductId        = product.Id,
                    MistralCode          = size.MistralCode,
                    MistralName          = size.MistralName,
                });
            }

            if (model.Image != null)
            {
                product.ImageUrl = await this.cloudService.UploadImageFromForm(model.Image);

                //await this.imageService.AddImage(model.Image, this.categoriesRepository.All().Where(c => c.Id == model.CategoryId).FirstOrDefault()?.Name);
            }

            await this.productsRepo.AddAsync(product);

            await this.productsRepo.SaveChangesAsync();
        }
示例#6
0
        public async Task <ActionResult <ProductViewModel> > GetProductDetails(ProductInputViewModel productInputViewModel)
        {
            if (productInputViewModel == null || productInputViewModel.Id.Equals(Guid.Empty))
            {
                throw new GalvException("Invalid product id", StatusCodes.Status400BadRequest);
            }
            var input  = _mapper.Map <ProductInputModel>(productInputViewModel);
            var result = await _productsBA.GetProductIncreaseViewcount(input);

            if (result == null)
            {
                throw new GalvException("Product id not found", StatusCodes.Status404NotFound);
            }
            return(Ok(_mapper.Map <ProductViewModel>(result)));
        }
        public void CreateProduct(ProductInputViewModel input)
        {
            var product = new Product
            {
                Name        = input.Name,
                Price       = input.Price,
                Category    = Enum.Parse <Category>(input.Category),
                Description = input.Description,
                Gender      = Enum.Parse <Gender>(input.Gender),
                ImageUrl    = input.ImageUrl
            };

            this.db.Products.Add(product);
            this.db.SaveChanges();
        }
示例#8
0
        public IActionResult Add(string id, ProductInputViewModel productInput)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(productInput));
            }
            var currentOrderId = id;
            var orderedProduct = _productsService.Add(currentOrderId,
                                                      productInput.ProductCode,
                                                      productInput.ProductName,
                                                      productInput.Count,
                                                      productInput.Weight);

            return(Redirect($"/Orders/Edit?id={orderedProduct.OrderId}"));
        }
示例#9
0
        public HttpResponse Add(ProductInputViewModel input)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (string.IsNullOrWhiteSpace(input.Name))
            {
                return(this.Redirect("/Products/Add"));
            }

            if (input.Name.Length < 4 || input.Name.Length > 20)
            {
                return(this.Redirect("/Products/Add"));
            }

            if (input.Description.Length > 10)
            {
                return(this.Redirect("/Products/Add"));
            }

            if (string.IsNullOrWhiteSpace(input.Category))
            {
                return(this.Redirect("/Products/Add"));
            }

            if (string.IsNullOrWhiteSpace(input.Gender))
            {
                return(this.Redirect("/Products/Add"));
            }

            if (input.Price < 0)
            {
                return(this.Redirect("/Products/Add"));
            }

            productService.CreateProduct(input);

            return(this.Redirect("/"));
        }
示例#10
0
        public async Task GetProductDetails_Does_not_exist()
        {
            //Setup
            var                   productId             = Guid.NewGuid();
            ProductModel          data                  = null;
            ProductInputViewModel productInputViewModel = new ProductInputViewModel()
            {
                Id = productId
            };
            ProductInputModel productInputModel = new ProductInputModel()
            {
                Id = productId
            };

            mapper.Setup(m => m.Map <ProductInputModel>(productInputViewModel)).Returns(productInputModel);
            productsBA.Setup(repo => repo.GetProductIncreaseViewcount(productInputModel)).Returns(Task.FromResult(data));

            //Action
            var controller = new ProductController(logger.Object, productsBA.Object, mapper.Object);
            var result     = await controller.GetProductDetails(productInputViewModel);
        }
示例#11
0
        public async Task <Product> UpdateProduct(ProductInputViewModel productInput)
        {
            var subCategory = await this.subCategoryService
                              .GetByName(productInput.SubCategory);

            Product product = new Product
            {
                Name        = productInput.Name,
                Description = productInput.Description,
                Gender      = productInput.Gender,
                ImageUrl    = productInput.ImageUrl,
                Price       = productInput.Price,
                Size        = productInput.Size,
                SubCategory = subCategory,
            };

            this.productRepository.Update(product);
            await this.productRepository.SaveChangesAsync();

            return(product);
        }
示例#12
0
        public async Task <IActionResult> Add([FromForm] ProductInputViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                inputModel.AvailableCategories = this.categoriesService.All().ToList();
                inputModel.AvailableAllergens  = this.allergensService.All().ToList();
                inputModel.AvailablePackages   = this.packagesService.All().ToList();
                return(this.View(inputModel));
            }

            try
            {
                await this.productsService.AddAsync(inputModel);

                return(this.Redirect("/"));
            }
            catch (Exception e)
            {
                this.logger.LogInformation(GlobalConstants.DefaultLogPattern, this.User.Identity.Name, e.Message, e.StackTrace);
                return(this.BadRequest());
            }
        }
示例#13
0
 public IActionResult Create(ProductInputViewModel model)
 {
     throw new NotImplementedException();
 }