public async Task <Response <AddProductDto> > AddAsync(AddProductBindingModel bindingModel, int userId)
        {
            var response = new Response <AddProductDto>();

            var user = await _userRepository.GetByAsync(x => x.Id == userId);

            if (user == null)
            {
                response.AddError(Key.User, Error.NotExist);
                return(response);
            }

            var product = _mapper.Map <Product>(bindingModel);

            product.User   = user;
            product.UserId = userId;

            var productAddSuccess = await _productRepository.AddAsync(product);

            if (!productAddSuccess)
            {
                response.AddError(Key.Product, Error.AddError);
                return(response);
            }

            var productDto = _mapper.Map <AddProductDto>(product);

            response.SuccessResult = productDto;

            return(response);
        }
示例#2
0
        public void AddNewProduct(AddProductBindingModel apbm)
        {
            Product product = Mapper.Map <AddProductBindingModel, Product>(apbm);

            this.Context.Products.Add(product);
            this.Context.SaveChanges();
        }
示例#3
0
        public AddProductBindingModel GetAllBrandsAndProductTypes()
        {
            var brands = this.DbContext
                         .Brands
                         .Select(this.Mapper.Map <BrandConciseViewModel>)
                         .ToList();

            var productTypes = this.DbContext
                               .ProductTypes
                               .Select(this.Mapper.Map <ProductTypeViewModel>)
                               .ToList();

            var brandsQuery = brands.Select(b => new SelectListItem()
            {
                Text = b.BrandName, Value = b.Id.ToString()
            });
            var productTypesQuery = productTypes.Select(b => new SelectListItem()
            {
                Text = b.TypeName, Value = b.Id.ToString()
            });

            var model = new AddProductBindingModel()
            {
                AllBrands       = brandsQuery.ToList(),
                AllProductTypes = productTypesQuery.ToList()
            };

            return(model);
        }
示例#4
0
        public async Task <IActionResult> AddAsync(AddProductBindingModel bindingModel)
        {
            var result = await _productService.AddAsync(bindingModel);

            if (result.ErrorOccurred)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
        public async Task <IActionResult> AddProductAsync(AddProductBindingModel model)
        {
            var(IsSuccessed, ErrorMsg) = await _productBLL.AddProductAsync(model.Title, model.Description, model.CategoryID, model.AttachmentUrls);

            return(Json(new
            {
                IsSuccessed,
                ErrorMsg
            }));
        }
        public async Task <IActionResult> AddAsync(AddProductBindingModel bindingModel)
        {
            var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
            var result = await _productService.AddAsync(bindingModel, userId);

            if (result.ErrorOccurred)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
示例#7
0
        public IActionResult Add(HttpSession session, AddProductBindingModel model,
                                 HttpResponse response)
        {
            var user = AuthenticationManager.IsAuthenticated(session);

            var service = new MenuService(Data.Data.Context);

            service.AddPizza(model, user);

            this.Redirect(response, "/menu/index");
            return(null);
        }
示例#8
0
        public void AddProduct(AddProductBindingModel bindingModel)
        {
            Knive knive = new Knive()
            {
                ImageUrl = bindingModel.ImageUrl,
                Name     = bindingModel.Name,
                Price    = bindingModel.Price
            };

            this.context.Knives.Add(knive);
            this.context.SaveChanges();
        }
示例#9
0
        public void AddProduct(AddProductBindingModel model)
        {
            var knife = new Knife()
            {
                Name     = model.Name,
                Price    = model.Price,
                ImageURL = model.ImageUrl
            };

            this.context.Knives.Add(knife);
            this.context.SaveChanges();
        }
示例#10
0
        public ActionResult AddProduct(AddProductBindingModel apbm)
        {
            if (ModelState.IsValid)
            {
                this.service.AddNewProduct(apbm);
                return(RedirectToAction("Panel", "Admin", new { area = "Admin" }));
            }

            AddProductViewModel addProductVm = this.service.GetAddProductVm();

            return(this.View(addProductVm));
        }
示例#11
0
        private async Task <Response <object> > ValidateAddingViewModel(AddProductBindingModel viewModel)
        {
            var  response      = new Response <object>();
            bool productExists = await _productRepository.ExistAsync(x =>
                                                                     x.Name == viewModel.Name);

            if (productExists)
            {
                response.AddError(Key.Product, Error.ProductAlreadyExists);
                return(response);
            }
            return(response);
        }
示例#12
0
        public void AddPizza(AddProductBindingModel model, User user)
        {
            var pizza = new Pizza()
            {
                Title     = model.Title,
                Recipe    = model.Recipe,
                ImageUrl  = model.ImageUrl,
                User      = user,
                UpVotes   = 0,
                DownVotes = 0
            };

            this.context.Pizzas.Add(pizza);
            this.context.SaveChanges();
        }
        public IActionResult Create(AddProductBindingModel bindingModel)
        {
            var productToCreate = new Models.Product
            {
                Name        = bindingModel.Name,
                Description = bindingModel.Description,
                Price       = bindingModel.Price,

                PictureURL = bindingModel.PictureURL,
                CreatedAt  = DateTime.Now
            };

            dbContext.Products.Add(productToCreate);
            dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#14
0
        public IActionResult CreateProduct(AddProductBindingModel bindingModel, int personID)
        {
            bindingModel.PersonID = personID;
            var productToCreate = new Product
            {
                Name       = bindingModel.Name,
                Price      = bindingModel.Price,
                Person     = dbContext.People.FirstOrDefault(p => p.ID == personID),
                PictureURL = "https://i.kinja-img.com/gawker-media/image/upload/s--UtjsCMpA--/c_scale,f_auto,fl_progressive,q_80,w_800/fnltdcfgfriq10dspggu.jpg",
                CreatedAt  = DateTime.Now
            };

            dbContext.Products.Add(productToCreate);
            dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#15
0
        public IActionResult Add(HttpSession session, HttpResponse response, AddProductBindingModel binding)
        {
            User user = AuthenticationManager.GetAuthenticatedUser(session.Id);

            if (user == null)
            {
                this.Redirect(response, "/login/login");
                return(null);
            }

            ProductsService service = new ProductsService(Data.Data.Context);

            service.AddProduct(binding);

            this.Redirect(response, "/admin/index");
            return(null);
        }
示例#16
0
 public List <AddProductViewModel> Read(AddProductBindingModel model)
 {
     using (var context = new AbstractSweetShopDatabase())
     {
         return(context.AddProducts
                .Where(rec => model == null || rec.ProductId == model.ProductId)
                .Select(rec => new AddProductViewModel
         {
             Id = rec.Id,
             ProductId = rec.ProductId,
             DateAdding = rec.DateAdding,
             ProductName = context.Products.FirstOrDefault(recP => recP.Id == model.ProductId).ProductName,
             Weight = rec.Weight
         })
                .ToList());
     }
 }
示例#17
0
 public void Create(AddProductBindingModel model)
 {
     using (var context = new AbstractSweetShopDatabase())
     {
         Product product = context.Products.FirstOrDefault(rec => rec.Id == model.ProductId);
         if (product == null)
         {
             throw new Exception("Продукт не найден");
         }
         product.FillWeight += model.Weight;
         context.AddProducts.Add(new AddProduct
         {
             ProductId  = model.ProductId,
             DateAdding = model.DateAdding,
             Weight     = model.Weight
         });
         context.SaveChanges();
     }
 }
示例#18
0
        public async Task <Response <object> > AddAsync(AddProductBindingModel bindingModel)
        {
            var response = await ValidateAddingViewModel(bindingModel);

            if (response.ErrorOccurred)
            {
                return(response);
            }
            var product = _mapper.Map <Product>(bindingModel);

            bool addSucceed = await _productRepository.AddAsync(product);

            if (!addSucceed)
            {
                response.AddError(Key.Product, Error.ProductAddError);
            }

            return(response);
        }
示例#19
0
        public IActionResult Order(AddProductBindingModel bindingModel)
        {
            var barcode  = long.Parse(bindingModel.Barcode);
            var quantity = int.Parse(bindingModel.Quantity);

            if (barcode.ToString().Length != 12)
            {
                return(this.RedirectToAction("/"));
            }

            var product = context.Products.FirstOrDefault(p => p.Barcode == barcode);

            if (product == null)
            {
                return(this.RedirectToAction("/"));
            }

            var user = context.Users.FirstOrDefault(u => u.Username == this.Identity.Username);

            if (user == null)
            {
                this.RedirectToAction("/");
            }


            var orderStatus = context.OrderStatuses.FirstOrDefault(s => s.Name == "Active");
            var order       = new Order()
            {
                OrderStatus   = orderStatus,
                Product       = product,
                Cashier       = user,
                Quantity      = quantity,
                OrderStatusId = 1,
            };

            context.Orders.Add(order);
            context.SaveChanges();

            return(this.RedirectToAction("/"));
        }
示例#20
0
        public async Task <IActionResult> AddProduct(AddProductBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                SetErrorMessage(CommonConstants.DangerMessage);

                return(this.AddProduct());
            }

            int generatedId = await this.productService.AddProductAsync(model);

            if (generatedId < 1)
            {
                SetErrorMessage(CommonConstants.DuplicateMessage);

                return(this.AddProduct());
            }

            SetSuccessMessage(string.Format(CommonConstants.SuccessMessage, CommonConstants.ProductSuffix));

            return(Redirect(string.Format(RedirectConstants.AdministratorAreaProductDetailsPage, generatedId)));
        }
示例#21
0
        public async Task <int> AddProductAsync(AddProductBindingModel model)
        {
            var checkForDuplicate = this.DbContext
                                    .Products
                                    .FirstOrDefault(x => x.ProductName == model.ProductName);

            if (checkForDuplicate != null)
            {
                return(ErrorId);
            }

            var product = this.Mapper.Map <Product>(model);

            if (product.HighLightVideoURL.Contains(CommonConstants.OriginalVideoUrlPart))
            {
                product.HighLightVideoURL = ModifyVideoURL_Embeded.ModifyEmbed(product.HighLightVideoURL);
            }

            await this.DbContext.Products.AddAsync(product);

            await this.DbContext.SaveChangesAsync();

            return(product.Id);
        }