public IActionResult CreateProduct(Product newProduct)
        {
            if (ModelState.IsValid)
            {
                dbContext.Add(newProduct);
                dbContext.SaveChanges();
                return(RedirectToAction("Products"));
            }
            List <Product> AllProducts = dbContext.Products.ToList();

            ViewBag.products = AllProducts;
            return(View("Products"));
        }
        public int AddProduct(Product product)
        {
            product.Id = 0;

            if (product.ProductOptions != null && product.ProductOptions.Any())
            {
                product.ProductOptions.ForEach(x => { x.Id = 0; });
            }

            _productContext.Add(product);
            SaveChanges();
            return(product.Id);
        }
Example #3
0
        public async Task <Product> AddAsync(Product item)
        {
            context.Add(item);
            await context.SaveChangesAsync();

            return(item);
        }
Example #4
0
        public void ShouldReturnAllProducts()
        {
            //Arange
            var options = new DbContextOptionsBuilder <ProductContext>()
                          .UseInMemoryDatabase(databaseName: "ShouldGetAllProducts")
                          .Options;

            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            _products = fixture.Create <IList <Product> >();

            using (var context = new ProductContext(options))
            {
                foreach (var product in _products)
                {
                    context.Add(product);
                    context.SaveChanges();
                }
            }

            //Act
            IList <Product> actualProducts;

            using (var context = new ProductContext(options))
            {
                var repository = new ProductRepository(context);
                actualProducts = repository.GetSubscibedProductsAsync().Result.ToList();
            }

            //Assert
            Assert.Equal(_products.Count, actualProducts.Count);
        }
        public async Task UpdateExistingProductSucceeds()
        {
            using var productContext = new ProductContext(GetDbSetOptions("test5"));
            var product = new Product {
                Id = "Test1", Description = "Test Product 1", Brand = "Brand A", Model = "Model A"
            };

            productContext.Add(product);
            productContext.SaveChanges();

            foreach (var entity in productContext.ChangeTracker.Entries())
            {
                entity.State = EntityState.Detached;
            }

            var updatedProduct = new Product {
                Id = "Test1", Description = "Updated Test Product", Brand = "Brand Z", Model = "Model Y"
            };

            await new ProductService(productContext).UpdateProductAsync(updatedProduct);
            Assert.AreEqual(productContext.Products.First().Id, updatedProduct.Id);
            Assert.AreEqual(productContext.Products.First().Description, updatedProduct.Description);
            Assert.AreEqual(productContext.Products.First().Brand, updatedProduct.Brand);
            Assert.AreEqual(productContext.Products.First().Model, updatedProduct.Model);
        }
Example #6
0
        public void Createproduct(Product product)
        {
            PhotoHelper photo1 = new PhotoHelper(product.PhotoAvatar1, product.ImageName1, product.PhotoFile1, product.ImageMimeType1);
            PhotoHelper photo2 = new PhotoHelper(product.PhotoAvatar2, product.ImageName2, product.PhotoFile2, product.ImageMimeType2);
            PhotoHelper photo3 = new PhotoHelper(product.PhotoAvatar3, product.ImageName3, product.PhotoFile3, product.ImageMimeType3);

            List <PhotoHelper> photoLst = new List <PhotoHelper>();

            photoLst.Add(photo1);
            photoLst.Add(photo2);
            photoLst.Add(photo3);

            foreach (var item in photoLst)
            {
                if (item.PhotoAvatar != null && item.PhotoAvatar.Length > 0)
                {
                    item.ImageMimeType = item.PhotoAvatar.ContentType;
                    item.ImageName     = Path.GetFileName(item.PhotoAvatar.FileName);

                    using (var memoryStream = new MemoryStream())
                    {
                        item.PhotoAvatar.CopyTo(memoryStream);
                        item.PhotoFile = memoryStream.ToArray();
                    }
                }
            }

            AddPhoto(product, photo1, photo2, photo3);

            _context.Add(product);
            _context.SaveChanges();
        }
        public int addColor(Color color)
        {
            var color1 = productContext.Add(color).Entity;

            productContext.SaveChanges();
            return(color1.Id);
        }
Example #8
0
        public async Task <IActionResult> Contacts(Contact login)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Subject"] = new SelectList(login.Subjects);
                return(View(login));
            }
            _context.Add(login);
            await _context.SaveChangesAsync();

            TempData["message"] =
                "Здравейте, " + login.FirstName + " " + login.FamilyName +
                "!\r\nДобре дошли в нашия сайт!\r\nВашият електронен адрес " +
                login.Email + " е добавен успешно.";
            return(RedirectToAction("OK", "Home"));
        }
        public int addSku(Sku sku)
        {
            var sku1 = productContext.Add(sku).Entity;

            productContext.SaveChanges();
            return(sku1.Id);
        }
 public override string Execute(List <string> parameters)
 {
     if (parameters.Count != 4)
     {
         return(ErrorType.PARAMETER_IS_NOT_SUFFICIENT.ToString());;
     }
     try
     {
         string         productCode = parameters[1];
         double         price       = double.Parse(parameters[2]);
         double         stock       = double.Parse(parameters[3]);
         Product        product     = new Product(productCode, price, stock);
         ProductContext context     = new ProductContext();
         bool           result      = context.Add(product);
         if (!result)
         {
             return(ErrorType.PRODUCT_ALREADY_EXISTS.ToString());
         }
         else
         {
             return($"Product created; code {productCode}, price {price}, stock {stock}");
         }
     }
     catch (System.Exception)
     {
         return(ErrorType.UNKNOWN_EXCEPTION.ToString());
     }
 }
Example #11
0
 public ValuesController(ProductContext context)
 {
     _context = context;
     if (_context.products.Count() == 0)
     {
         _context.Add(new Product {
             Description = "Dette er produktet til dig med ordblindhed", Price = 699.99, AdvancedDescription = tempAdvancedDescription, Picture = "https://dyslexiaida.org/wp-content/uploads/2016/05/Not-Stupid-Not-Lazy-Cover-Final-sm.jpg"
         });
         _context.Add(new Product {
             Description = "Dette er produktet til dig med svagt syn", Price = 1250, AdvancedDescription = tempAdvancedDescription, Picture = "https://res.cloudinary.com/liingo/image/upload/c_fill,g_center,h_339,w_990,q_85/754317164787_2.jpg"
         });
         _context.Add(new Product {
             Description = "Dette er et testprodukt", Price = 69, AdvancedDescription = tempAdvancedDescription, Picture = "https://images.sftcdn.net/images/t_app-cover-l,f_auto/p/ce2ece60-9b32-11e6-95ab-00163ed833e7/260663710/the-test-fun-for-friends-screenshot.jpg"
         });
         _context.SaveChanges();
     }
 }
Example #12
0
        public async Task <IActionResult> Create([Bind("Id,PointId,Data,UserId,Price,Coment")] Money money)
        {
            if (ModelState.IsValid)
            {
                money.Date   = DateTime.Now;
                money.UserId = _context.Users.First(p => p.Login == User.Identity.Name).Id;
                _context.Add(money);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            /* ViewData["PointId"] = new SelectList(_context.PointOfSales, "Id", "Id", money.PointId);
             * ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", money.UserId);
             * return View(money);*/
            return(RedirectToAction(nameof(Index)));
        }
        public void AddProduct(ProductEntity productToAdd)
        {
            if (productToAdd == null)
            {
                throw new ArgumentNullException(nameof(productToAdd));
            }

            _context.Add(productToAdd);
        }
Example #14
0
        public async Task <IActionResult> Create([Bind("ID,Name,IsDelete")] Type @type)
        {
            _context.Add(@type);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));

            return(View(@type));
        }
Example #15
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         _context.Add(Product);
         _context.SaveChanges();
     }
     return(Page());
 }
Example #16
0
 public IActionResult AddProduct(Product product)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(product);
         dbContext.SaveChanges();
         return(RedirectToAction("ProdPage"));
     }
     return(RedirectToAction("ProdPage"));
 }
Example #17
0
        public async Task <ActionResult <Product> > PostProduct(Product product)
        {
            _context.Add(product);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(GetProduct),
                       new { Id = product.Id },
                       product));
        }
Example #18
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                return(RedirectToPage("/Index")); // TODO: Change to login redirect
            }

            IList <Cart> cartItem = await _context.CartItems.ToListAsync();

            // if the amount of days passed since order was created can make order is allow user to add to cart, otherwise redirect
            if (user.CoolOffDate <= DateTime.Now)
            {
                var emptyCartItem = new Cart();

                var entry = _context.Add(emptyCartItem);
                // assign a userID to the order, so we know which cart items to remove
                CartVM.PurchaserID = user.Id;
                // if the user edits the cart to have a value more than 1 then redirect to the same page
                if (CartVM.Quantity > 1)
                {
                    return(RedirectToPage("./Index"));
                }
                entry.CurrentValues.SetValues(CartVM);
                await _context.SaveChangesAsync();

                var cartItemList = await _context.CartItems
                                   .Include(t => t.TrainingRoutine)
                                   .ThenInclude(p => p.PersonalTrainingSession)
                                   .ToListAsync();


                // grab the length of the routine for the newly created order
                int routineLengthChosen = 0;// _context.CartItems.Where(o => o.TrainingRoutineID == CartVM.TrainingRoutineID).OrderByDescending(o => o.CartID).FirstOrDefault().TrainingRoutine.PersonalTrainingSession.LengthOfRoutine;
                routineLengthChosen = cartItemList.OrderByDescending(o => o.CartID).FirstOrDefault().TrainingRoutine.PersonalTrainingSession.LengthOfRoutine;

                // set the cool off date before we can order to be the length of the routine length chosen
                user.CoolOffDate = DateTime.Now.AddDays(routineLengthChosen);
                await _userManager.UpdateAsync(user);

                PopulateProductDropDownList(_context, emptyCartItem.TrainingRoutineID);

                // returns to the list of current orders
                //return RedirectToPage(); <---return to add more if needed
                // return RedirectToPage("./Index"); previous, if go back two directories and to view orders dont work
                return(RedirectToPage("/Products/Orders/ManageCart/ViewCart"));
            }
            return(RedirectToPage("/Identity/Account/Login"));
        }
        public async Task <IActionResult> Create([Bind("clientsID,orderID,clName,clLastName,clPhone,clEmail,clStreet,clCity,clPostalcode")] Clients clients)
        {
            if (ModelState.IsValid)
            {
                _context.Add(clients);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(clients));
        }
Example #20
0
        // public IUnitOfWork UnitOfWork => _context;

        public Product Add(Product product)
        {
            var result = new Product()
            {
                Id = 66
            };

            _context.Add(result);
            _context.SaveChanges();
            return(result);
        }
        public async Task <IActionResult> Create([Bind("ordersID,productID,ordQuantity,ordDate,ordDescription")] Orders orders)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orders);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orders));
        }
Example #22
0
        public async Task <IActionResult> Create([Bind("Id,Brand,Model,Price,Description,SalesCounter,InStock,PathToImage")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
        public async Task <IActionResult> Create([Bind("Id,IdCart,IdProduct,Number")] InCart inCart)
        {
            if (ModelState.IsValid)
            {
                _context.Add(inCart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(inCart));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Enterprise enterprise)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enterprise);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(enterprise));
        }
Example #25
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,UnitPrice,Quantity,StockValue")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Example #26
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,Qauntity,Price")] ProductViewModel productViewModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productViewModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(productViewModel));
        }
Example #27
0
        public async Task <IActionResult> Create([Bind("ID,Title,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Example #28
0
        public async Task <IActionResult> Create([Bind("ID,ProductName,Description,ImagePath,UnitPrice")] Arival arival)
        {
            if (ModelState.IsValid)
            {
                _context.Add(arival);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(arival));
        }
        public async Task <IActionResult> Create([Bind("ID,CheckIn,CheckOut,CreateTime,Total,IsDelete")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                _context.Add(booking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(booking));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Category,SubCategory,Volume,ProductionYear,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(AdminList)));
            }
            return(View(product));
        }