public ActionResult Create([Bind(Include = "ArticleId,ArticleName,Description,Price,Image,Stock")] Products products)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(products);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(products));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "ProducerId,ProducerName,FirstName,LastName")] Producer producer)
        {
            if (ModelState.IsValid)
            {
                db.Producers.Add(producer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(producer));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ProductId,CategoryId,Name,Description,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId);
            return(View(product));
        }
Ejemplo n.º 4
0
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "CategoryName", product.CategoryId);
            ViewBag.SuppliedId = new SelectList(db.Suppliers, "Id", "Company", product.SuppliedId);
            return(View(product));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "Id,OrderDate,SuppplierId,CreatedBy,CreatedDate,ExpectedDate,ShippingFee,Taxes,PaymentDate,PaymentAmount,PaymentMethod,Notes,OrderSubTotal,OrderTotal,SubmittedBy,SubmittedDate,ClosedBy,ClosedDate,IsCompleted,IsSubmitted,IsNew,OrderStatusId")] PurchaseOrder purchaseOrder)
        {
            if (ModelState.IsValid)
            {
                db.PurchaseOrders.Add(purchaseOrder);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CreatedBy     = new SelectList(db.Employees, "Id", "FirstName", purchaseOrder.CreatedBy);
            ViewBag.OrderStatusId = new SelectList(db.OrderStatus, "Id", "Status", purchaseOrder.OrderStatusId);
            ViewBag.SuppplierId   = new SelectList(db.Suppliers, "Id", "Company", purchaseOrder.SuppplierId);
            return(View(purchaseOrder));
        }
Ejemplo n.º 6
0
        //заполнение быза данных
        private void uploadToDB()
        {
            using (StoreDB db = new StoreDB())
            {
                if (db.Products.Count() != 0)
                {
                    return;
                }
                Category mac    = new Category("Mac");
                Category ipad   = new Category("iPad");
                Category iphone = new Category("iPhone");
                Category watch  = new Category("Watch");
                Category tv     = new Category("TV");
                Category music  = new Category("Music");
                db.Categories.Add(mac);
                db.Categories.Add(ipad);
                db.Categories.Add(iphone);
                db.Categories.Add(watch);
                db.Categories.Add(tv);
                db.Categories.Add(music);
                db.SaveChanges();

                db.Products.AddRange(new List <Product> {
                    new Product("MacBook Air", 1299, mac),
                    new Product("MacBook Pro 13\"", 2399, mac),
                    new Product("MacBook Pro 16\"", 2799, mac),
                    new Product("iMac", 2299, mac),
                    new Product("iMac Pro", 4999, mac),
                    new Product("iPad Pro", 999, ipad),
                    new Product("iPad Air", 499, ipad),
                    new Product("iPad", 329, ipad),
                    new Product("iPad Mini", 399, ipad),
                    new Product("iPhone 11 Pro", 999, iphone),
                    new Product("iPhone 11", 699, iphone),
                    new Product("iPhone xR", 599, iphone),
                    new Product("iPhone 8", 449, iphone),
                    new Product("Watch Series 5", 399, watch),
                    new Product("Watch Nike", 399, watch),
                    new Product("Watch Series 3", 399, watch),
                    new Product("TV 4K", 199, tv),
                    new Product("TV HD", 149, tv),
                    new Product("Airpods Pro", 249, music),
                    new Product("Airpods", 199, music),
                    new Product("Home Pod", 299, music)
                });
                db.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        private void createOrderButton_Click(object sender, EventArgs e)
        {
            double totalCost = 0;

            for (int i = 0; i < dataGridView.Rows.Count; i++)
            {
                totalCost = totalCost + (double)dataGridView.Rows[i].Cells[2].Value;
            }

            string resultString = $"Create an order of {dataGridView.Rows.Count} products with a total value - {totalCost}";

            DialogResult result = MessageBox.Show(resultString, "Accept order", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                using (StoreDB db = new StoreDB())
                {
                    Order order = new Order(db.Users.Find(GlobalVars.CurrentUser.userID), totalCost);

                    foreach (var product in GlobalVars.ShoppingCartList)
                    {
                        order.Products.Add(db.Products.Find(product.ProductId));
                    }
                    db.Orders.Add(order);
                    db.SaveChanges();
                    MessageBox.Show("Your order is created. Waiting for moderator to check");
                }
                dataGridView.DataSource = null;
                GlobalVars.ShoppingCartList.Clear();
                shoppingHistoryButton_Click(sender, e);
            }
        }
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);
            try
            {
                if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(order));
                }
                else
                {
                    order.Username  = User.Identity.Name;
                    order.OrderDate = DateTime.Now;
                    //Save Order
                    StoreDB.Orders.Add(order);
                    StoreDB.SaveChanges();
                    //Process the order
                    var cart = ShoppingCart.GetCart(this.HttpContext, StoreDB);
                    cart.CreateOrder(order);
                    return(RedirectToAction("Complete", new { id = order.OrderId }));
                }
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
Ejemplo n.º 9
0
        public ActionResult EditSection([Bind(Include = "BackgroundColour,ButtonColour,ButtonTextColour,TitleColour,MainTextColour,SectionBackgroundColour,SectionTextColour,SectionTextUnderlineColour")] tbl_UserControl tbl_UserControl, int id)
        {
            if (ModelState.IsValid)
            {
                List <tbl_UserControl> lstControlsl = db.tbl_UserControl.ToList();
                tbl_UserControl        userControl  = lstControlsl.Single(it => it.Id == id);

                string typeId = userControl.TypeId;
                string pageId = userControl.PageId;

                using (var newContext = new StoreDB())
                {
                    var list = newContext.tbl_UserControl;

                    foreach (var el in list.Where(el => (el.TypeId == typeId) && (el.PageId == pageId)))
                    {
                        el.BackgroundColour           = tbl_UserControl.BackgroundColour;
                        el.ButtonColour               = tbl_UserControl.ButtonColour;
                        el.ButtonTextColour           = tbl_UserControl.ButtonTextColour;
                        el.TitleColour                = tbl_UserControl.TitleColour;
                        el.MainTextColour             = tbl_UserControl.MainTextColour;
                        el.SectionBackgroundColour    = tbl_UserControl.SectionBackgroundColour;
                        el.SectionTextColour          = tbl_UserControl.SectionTextColour;
                        el.SectionTextUnderlineColour = tbl_UserControl.SectionTextUnderlineColour;
                    }

                    newContext.SaveChanges();

                    HelperController.RemoveCache();
                }
                return(Redirect("/Admin/GetActionResultForPage/" + Request.QueryString["pageType"]));
            }
            return(View(tbl_UserControl));
        }
Ejemplo n.º 10
0
        public ActionResult Create([Bind(Include = "Id,Title,Subtitle,MainText,ButtonText,ImageUrl,UrlLink,PageId,TypeId,Active,BackgroundColour,ButtonColour,ButtonTextColour,TitleColour,MainTextColour")] tbl_UserControl tbl_UserControl)
        {
            if (ModelState.IsValid)
            {
                tbl_UserControl.PageId = Request.QueryString["pageType"];
                tbl_UserControl.TypeId = Request.QueryString["TypeId"];

                db.tbl_UserControl.Add(tbl_UserControl);
                db.SaveChanges();

                HelperController.RemoveCache();

                return(Redirect("/Admin/GetActionResultForPage/" + Request.QueryString["pageType"]));
            }

            return(View(tbl_UserControl));
        }
Ejemplo n.º 11
0
        public ActionResult DeleteConfirmed(int id)
        {
            Album album = StoreDB.Albums.Find(id);

            StoreDB.Albums.Remove(album);
            StoreDB.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 12
0
        public void AddSupplier(Supplier supplier)
        {
            using (var db = new StoreDB())
            {
                SUPPLIER sup = Mapper.Map <SUPPLIER>(supplier);

                db.SUPPLIERS.Add(sup);
                db.SaveChanges();
            }
        }
Ejemplo n.º 13
0
        public void InsertTransaction(PurchaseTransaction purchase)
        {
            using (var db = new StoreDB())
            {
                PURCHASE_TRANSACTIONS prod = Mapper.Map <PURCHASE_TRANSACTIONS>(purchase);


                db.Set <PURCHASE_TRANSACTIONS>().Add(prod);
                db.SaveChanges();
            }
        }
Ejemplo n.º 14
0
        private void isUncheckedButton_Click(object sender, EventArgs e)
        {
            using (StoreDB db = new StoreDB())
            {
                db.Orders.First(o => o.orderId == ((Order)dataGridView.CurrentRow.DataBoundItem).orderId).IsChecked = false;
                db.SaveChanges();
                var allOrders = from order in db.Orders
                                select order;

                dgOrdersAdmin(allOrders.ToList());
            }
        }
Ejemplo n.º 15
0
 private void SeedCategories(StoreDB context)
 {
     for (int i = 1; i <= 5; i++)
     {
         var category = new Category()
         {
             Name = "Kategoria " + i.ToString()
         };
         context.Set <Category>().AddOrUpdate(category);
     }
     context.SaveChanges();
 }
Ejemplo n.º 16
0
        public void AddProduct(Product product)
        {
            using (var db = new StoreDB())
            {
                PRODUCT prod = Mapper.Map <PRODUCT>(product);
                prod.ProductCategoryId = 1;
                prod.ProductType       = 1;
                //prod.ProductUoM = 1;

                db.PRODUCTS.Add(prod);
                db.SaveChanges();
            }
        }
Ejemplo n.º 17
0
        public JsonResult SaveCategoryData(Category category)
        {
            ResponseMessage responseMessage;

            if (!string.IsNullOrEmpty(category.CategoryName))
            {
                var checkCategory = db.Categories.Where(c => c.CategoryName == category.CategoryName).ToList();

                if (checkCategory.Count == 0)
                {
                    db.Categories.Add(category);
                    var response = db.SaveChanges();
                    responseMessage = new ResponseMessage()
                    {
                        Success = true,
                        Message = "Category information successfully saved."
                    };
                }
                else
                {
                    responseMessage = new ResponseMessage()
                    {
                        Success = false,
                        Message = "Category " + category.CategoryName + " already exists in database."
                    };
                }
                return(Json(responseMessage));
            }
            else
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Category name is empty"
                };
                return(Json(responseMessage));
            }
        }
Ejemplo n.º 18
0
        public void registrationButton_Click(object sender, EventArgs e)
        {
            using (StoreDB db = new StoreDB())
            {
                foreach (var user in db.Users)
                {
                    if (user.mail == loginTextbox.Text)
                    {
                        MessageBox.Show("A user with this email has already been created.", "Error");
                        return;
                    }
                }

                User tempUser = db.Users.Add(new User(string.Format(firstNameTextbox.Text + " " + lastNameTextbox.Text),
                                                      loginTextbox.Text,
                                                      Convert.ToDateTime(birthdayTextbox.Text),
                                                      EncodingPassword.Encryption(passwordTextbox.Text)));
                db.SaveChanges();

                if (GlobalVars.CurrentUser.name == null)
                {
                    MessageBox.Show("Registration is complited. Use your login and password to autorization.");
                    GlobalVars.registrationForm.Visible = false;
                    GlobalVars.autorizationForm.Visible = true;
                }
                else
                {
                    DialogResult dialogResult = MessageBox.Show("Make new user as manager ?", "Registration is complited", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        tempUser.IsManager = true;
                        db.SaveChanges();
                    }
                    Hide();
                }
            }
        }
Ejemplo n.º 19
0
        //// [ValidateAntiForgeryToken]
        public JsonResult Create(Supplier supplier)
        {
            ////if (ModelState.IsValid)
            ////{
            ////    db.Suppliers.Add(supplier);
            ////    db.SaveChanges();
            ////    return RedirectToAction("Index");
            ////}
            ////var data = supplier;

            db.Suppliers.Add(supplier);
            var response = db.SaveChanges();


            var responseMessage = new
            {
                Success = true,
                Message = "Supplier information successfully saved."
            };



            return(Json(responseMessage));
        }
Ejemplo n.º 20
0
 private void SeedProducers(StoreDB context)
 {
     for (int i = 1; i <= 3; i++)
     {
         var producer = new Producer()
         {
             ProducerId = i,
             Name       = "Producent " + i.ToString(),
             FirstName  = "Tom",
             LastName   = "Drugi"
         };
         context.Set <Producer>().AddOrUpdate(producer);
     }
     context.SaveChanges();
 }
Ejemplo n.º 21
0
        public ActionResult ProcessOrder(FormCollection frc)
        {
            List <Cart> lsCart = (List <Cart>)Session[strCart];
            //1. Savew the order into Order Table
            Order order = new Order()
            {
                FirstName  = frc["cusFName"],
                LastName   = frc["cusLName"],
                Phone      = frc["cusPhone"],
                Email      = frc["cusEmail"],
                Address    = frc["cusAddress"],
                City       = frc["cusCity"],
                State      = frc["cusState"],
                PostalCode = frc["cusPostalCode"],
                OrderDate  = DateTime.Now,
            };

            storeDB.Orders.Add(order);
            storeDB.SaveChanges();
            //2. Save the order detail into the Order Detail table
            foreach (Cart cart in lsCart)
            {
                OrderDetail orderDetail = new OrderDetail()
                {
                    OrderId   = order.OrderId,
                    ProductId = cart.Product.ProductId,
                    Quantity  = cart.Quantity,
                    UnitPrice = cart.Product.Price
                };
                storeDB.OrderDetails.Add(orderDetail);
                storeDB.SaveChanges();
            }
            //3.Remove the shopping cart session
            Session.Remove(strCart);
            return(View("OrderSuccess"));
        }
Ejemplo n.º 22
0
 private void SeedPictures(StoreDB context)
 {
     for (int i = 0; i < 20; i++)
     {
         context.Set <Picture>().AddOrUpdate(new Picture {
             Name = "pict1.jpg", ProductId = 1 + 3 * i
         });
         context.Set <Picture>().AddOrUpdate(new Picture {
             Name = "pict2.jpg", ProductId = 2 + 3 * i
         });
         context.Set <Picture>().AddOrUpdate(new Picture {
             Name = "pict3.jpg", ProductId = 3 + 3 * i
         });
     }
     context.SaveChanges();
 }
Ejemplo n.º 23
0
 public ActionResult Create([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album)
 {
     if (ModelState.IsValid)
     {
         if (album.Title != null && album.Title.Trim() != "" && album.Price >= 0)
         {
             StoreDB.Albums.Add(album);
             StoreDB.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(RedirectToAction("InvalidRequest", "Error"));
     }
     ViewBag.ArtistId = new SelectList(StoreDB.Artists, "ArtistId", "Name", album.ArtistId);
     ViewBag.GenreId  = new SelectList(StoreDB.Genres, "GenreId", "Name", album.GenreId);
     return(View(album));
 }
Ejemplo n.º 24
0
 private void isNotManagerButton_Click(object sender, EventArgs e)
 {
     if (((User)dataGridView.CurrentRow.DataBoundItem).userID == GlobalVars.CurrentUser.userID)
     {
         MessageBox.Show("You can not change your status manager.");
         return;
     }
     using (StoreDB db = new StoreDB())
     {
         db.Users.First(o => o.userID == ((User)dataGridView.CurrentRow.DataBoundItem).userID).IsManager = false;
         db.SaveChanges();
         List <User> users = db.Users
                             .OrderBy(y => y.userID)
                             .OrderBy(x => x.IsManager)
                             .ToList();
         dataGridView.DataSource = users;
         dataGridView.Columns["password"].Visible = false;
         dataGridView.Columns["Orders"].Visible   = false;
     }
 }
Ejemplo n.º 25
0
        private void SeedProducts(StoreDB context)
        {
            int sizes  = Repository.Services.ProductService.AvailableSizes.Length;
            int colors = Repository.Services.ProductService.AvailableColors.Length;

            for (int i = 1; i <= 60; i++)
            {
                var product = new Product()
                {
                    Category   = context.Categories.Find(i % 5 + 1),
                    ProducerId = (i - 1) / 20 + 1,
                    Colors     = i % ((1 << colors) - 1) + 1,
                    Sizes      = i % ((1 << sizes) - 1) + 1,
                    Name       = "Produkt " + i.ToString(),
                    Price      = i / 10M,
                    Amount     = (i < 5 ? 0 : i)
                };
                context.Set <Product>().AddOrUpdate(product);
            }
            context.SaveChanges();
        }
        //// [ValidateAntiForgeryToken]
        public JsonResult Create(ShippingCompany shippingCompany)
        {
            ResponseMessage responseMessage;

            if (string.IsNullOrEmpty(shippingCompany.Company))
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Company is required."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }

            if (string.IsNullOrEmpty(shippingCompany.Email))
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Email is required."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }


            var checkCompany = db.ShippingCompanies.Where(e => e.Company == shippingCompany.Company).ToList();
            var checkEmail   = db.ShippingCompanies.Where(e => e.Email == shippingCompany.Email).ToList();

            if (checkCompany.Count != 0)
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Company " + shippingCompany.Company + " already exists."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }
            if (checkEmail.Count != 0)
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Email " + shippingCompany.Email + " already exists."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }

            try
            {
                db.ShippingCompanies.Add(shippingCompany);
                //var response = db.SaveChanges();
                db.SaveChanges();
                responseMessage = new ResponseMessage()
                {
                    Success = true,
                    Message = "Shipping Company information successfully saved."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var a = ex;
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Error: " + ex.Message
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 27
0
        public ActionResult Create(Employee employee)
        {
            //validation for firsat name, email, login-this validation will make sure textbox is not null

            ResponseMessage responseMessage;

            if (string.IsNullOrEmpty(employee.FirstName))
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "First Name is required."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrEmpty(employee.Email))
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Email Name is required."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrEmpty(employee.Login))
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Login Name is required."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }



            //validation as will - this validation will look duplicate data. such as same email or login
            //id can not be created again

            var checkLogin = db.Employees.Where(e => e.Login == employee.Login).ToList();
            var checkEmail = db.Employees.Where(e => e.Email == employee.Email).ToList();

            if (checkLogin.Count != 0)
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Login " + employee.Login + " already exists."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }
            if (checkEmail.Count != 0)
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Email " + employee.Email + " already exists."
                };
                return(Json(responseMessage, JsonRequestBehavior.AllowGet));
            }
            // lastly, if all the validaion parts done/checked successfully, call will go to success block cotherwise error.
            try
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                responseMessage = new ResponseMessage()
                {
                    Success = true,
                    Message = "Employee information successfully saved."
                };
            }
            catch (Exception)
            {
                responseMessage = new ResponseMessage()
                {
                    Success = false,
                    Message = "Something went wrong."
                };
            }

            return(Json(responseMessage, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 28
0
 public void Save()
 {
     context.SaveChanges();
 }