public ActionResult ShowProducts()
        {
            #region ErrorMessages
            InsertError errorEmptyProductId = TempData["errorEmptyProductId"] as InsertError;
            if (errorEmptyProductId != null)
            {
                ViewData["ErrorMessageEmptyProductId"] = errorEmptyProductId.ErrorMessageEmptyProductId;
            }

            InsertError errorEmptyEditProductId = TempData["errorEmptyEditProductId"] as InsertError;
            if (errorEmptyEditProductId != null)
            {
                ViewData["ErrorMessageEmptyEditProductId"] = errorEmptyEditProductId.ErrorMessageEmptyEditProductId;
            }

            InsertError errorEmptyAmountZeroProductId = TempData["errorEmptyAmountZeroProductId"] as InsertError;
            if (errorEmptyAmountZeroProductId != null)
            {
                ViewData["ErrorMessageEmptyAmountZeroProductId"] = errorEmptyAmountZeroProductId.ErrorMessageEmptyAmountZeroProductId;
            }

            #region ErrorsChangeProductAmount

            InsertError errorEmptyAmountChangeProductId = TempData["errorEmptyAmountChangeProductId"] as InsertError;
            if (errorEmptyAmountChangeProductId != null)
            {
                ViewData["ErrorMessageEmptyAmountChangeProductId"] = errorEmptyAmountChangeProductId.ErrorMessageEmptyAmountChangeProductId;
            }

            InsertError errEmptyAmount = TempData["errorEmptyAmount"] as InsertError;
            if (errEmptyAmount != null)
            {
                ViewData["ErrorMessageEmptyAmount"] = errEmptyAmount.ErrorMessageEmptyAmount;
            }

            InsertError errWrongAmount = TempData["errorWrongAmount"] as InsertError;
            if (errWrongAmount != null)
            {
                ViewData["ErrorMessageWrongAmount"] = errWrongAmount.ErrorMessageWrongAmount;
            }
            #endregion
            #region ErrorsAddProductAmount
            InsertError errorEmptyAmountAddProductId = TempData["errorEmptyAmountAddProductId"] as InsertError;
            if (errorEmptyAmountAddProductId != null)
            {
                ViewData["ErrorMessageEmptyAmountAddProductId"] = errorEmptyAmountAddProductId.ErrorMessageEmptyAmountAddProductId;
            }

            InsertError errEmptyAddAmount = TempData["errorEmptyAddAmount"] as InsertError;
            if (errEmptyAddAmount != null)
            {
                ViewData["ErrorMessageEmptyAddAmount"] = errEmptyAddAmount.ErrorMessageEmptyAddAmount;
            }

            InsertError errWrongAddAmount = TempData["errorWrongAddAmount"] as InsertError;
            if (errWrongAddAmount != null)
            {
                ViewData["ErrorMessageWrongAddAmount"] = errWrongAddAmount.ErrorMessageWrongAddAmount;
            }
            #endregion
            #region ErrorsSetNewProductPrice
            InsertError errorEmptyPriceProductId = TempData["errorEmptyPriceProductId"] as InsertError;
            if (errorEmptyPriceProductId != null)
            {
                ViewData["ErrorMessageEmptyPriceProductId"] = errorEmptyPriceProductId.ErrorMessageEmptyPriceProductId;
            }

            InsertError errEmptyPrice = TempData["errorEmptyPrice"] as InsertError;
            if (errEmptyPrice != null)
            {
                ViewData["ErrorMessageEmptyPrice"] = errEmptyPrice.ErrorMessageEmptyPrice;
            }

            InsertError errWrongPrice = TempData["errorWrongPrice"] as InsertError;
            if (errWrongPrice != null)
            {
                ViewData["ErrorMessageWrongPrice"] = errWrongPrice.ErrorMessageWrongPrice;
            }
            #endregion

            #endregion

            var model = new ProductModel();

            using (var context = new WHOLESALE_STOREEntities())
            {
                foreach (var pr in context.PRODUCT.OrderBy(p => p.NAME).ToList())
                {
                    var category = new Category()
                    {
                        Name = pr.CATEGORY.NAME
                    };
                    var unit = new Unit()
                    {
                        Name = pr.UNIT.NAME
                    };

                    model.Products.Add(new Product()
                    {
                        Id = pr.ID, Name = pr.NAME, BarCode = pr.BARCODE, Amount = pr.AMOUNT, Price = pr.PRICE, Category = category, Unit = unit
                    });
                }
            }

            var view = View("~/Views/Product/ShowProducts.cshtml", model);

            // view.ViewBag.userId = userId;

            return(view);
        }
        public ActionResult AddProduct(int?category)
        {
            #region ErrorMessages
            InsertError errName = TempData["errorName"] as InsertError;
            if (errName != null)
            {
                ViewData["ErrorMessageEmptyName"] = errName.ErrorMessageEmptyName;
            }

            InsertError errorEmptyBarCode = TempData["errorEmptyBarCode"] as InsertError;
            if (errorEmptyBarCode != null)
            {
                ViewData["ErrorMessageEmptyBarCode"] = errorEmptyBarCode.ErrorMessageEmptyBarCode;
            }

            InsertError errWrongBarCode = TempData["errorWrongBarCode"] as InsertError;
            if (errWrongBarCode != null)
            {
                ViewData["ErrorMessageWrongBarCode"] = errWrongBarCode.ErrorMessageWrongBarCode;
            }

            InsertError errEmptyAmount = TempData["errorEmptyAmount"] as InsertError;
            if (errEmptyAmount != null)
            {
                ViewData["ErrorMessageEmptyAmount"] = errEmptyAmount.ErrorMessageEmptyAmount;
            }


            InsertError errWrongAmount = TempData["errorWrongAmount"] as InsertError;
            if (errWrongAmount != null)
            {
                ViewData["ErrorMessageWrongAmount"] = errWrongAmount.ErrorMessageWrongAmount;
            }

            InsertError errEmptyPrice = TempData["errorEmptyPrice"] as InsertError;
            if (errEmptyPrice != null)
            {
                ViewData["ErrorMessageEmptyPrice"] = errEmptyPrice.ErrorMessageEmptyPrice;
            }

            InsertError errWrongPrice = TempData["errorWrongPrice"] as InsertError;
            if (errWrongPrice != null)
            {
                ViewData["ErrorMessageWrongPrice"] = errWrongPrice.ErrorMessageWrongPrice;
            }

            InsertError errEmptyCategory = TempData["errorEmptyCategory"] as InsertError;
            if (errEmptyCategory != null)
            {
                ViewData["ErrorMessageEmptyCategory"] = errEmptyCategory.ErrorMessageEmptyCategory;
            }

            InsertError errEmptyUnit = TempData["errorEmptyUnit"] as InsertError;
            if (errEmptyUnit != null)
            {
                ViewData["ErrorMessageEmptyUnit"] = errEmptyUnit.ErrorMessageEmptyUnit;
            }
            #endregion

            var model = new ProductModel();

            using (var context = new WHOLESALE_STOREEntities())
            {
                foreach (var ct in context.CATEGORY.ToList())
                {
                    model.Categories.Add(new Category()
                    {
                        Name = ct.NAME, Id = ct.ID
                    });
                }
                foreach (var unit in context.UNIT.ToList())
                {
                    model.Units.Add(new Unit()
                    {
                        Name = unit.NAME, Id = unit.ID
                    });
                }
            }
            return(View("~/Views/Product/AddProduct.cshtml", model));
        }
        public ActionResult SaveEditedCustomer(int customerId, string name, string phoneNumber, string email, string address)
        {
            var model = new CustomerModel();

            #region ErrorMessages
            if (String.IsNullOrEmpty(name))
            {
                InsertError errorName = new InsertError();
                errorName.ErrorMessageEmptyName = "Enter the name!";
                TempData["errorName"]           = errorName;
            }

            if (String.IsNullOrEmpty(phoneNumber))
            {
                InsertError errorEmptyPhone = new InsertError();
                errorEmptyPhone.ErrorMessageEmptyPhoneNumber = "Enter the phone number!";
                TempData["errorEmptyPhone"] = errorEmptyPhone;
            }

            else if (Regex.Match(phoneNumber, @"^(\+[0-9]{12})$").Success == false)
            {
                InsertError errorWrongPhone = new InsertError();
                errorWrongPhone.ErrorMessageWrongPhone = "Wrong phone number!";
                TempData["errorWrongPhone"]            = errorWrongPhone;
            }

            if (String.IsNullOrEmpty(email))
            {
                InsertError errorEmail = new InsertError();
                errorEmail.ErrorMessageEmptyEmail = "Enter Email!";
                TempData["errorEmail"]            = errorEmail;
            }

            else if (new EmailAddressAttribute().IsValid(email) == false)
            {
                InsertError errorWrongEmail = new InsertError();
                errorWrongEmail.ErrorMessageWrongEmail = "Wrong Email!";
                TempData["errorWrongEmail"]            = errorWrongEmail;
            }

            if (String.IsNullOrEmpty(address))
            {
                InsertError errorAddress = new InsertError();
                errorAddress.ErrorMessageEmptyAddress = "Enter the address!";
                TempData["errorAddress"] = errorAddress;
            }
            #endregion

            if (TempData["errorName"] != null ||
                TempData["errorEmptyPhone"] != null ||
                TempData["errorWrongPhone"] != null ||
                TempData["errorEmail"] != null ||
                TempData["errorAddress"] != null ||
                TempData["errorWrongEmail"] != null)
            {
                model.CustomerObject.Id          = customerId;
                model.CustomerObject.Name        = name;
                model.CustomerObject.PhoneNumber = phoneNumber;
                model.CustomerObject.Email       = email;
                model.CustomerObject.Address     = address;

                return(EditCustomer(model));
            }

            using (var context = new WHOLESALE_STOREEntities())
            {
                var customerDB = context.CUSTOMER.Find(customerId);

                customerDB.NAME         = name;
                customerDB.PHONE_NUMBER = phoneNumber;
                customerDB.EMAIL        = email;
                customerDB.C_ADDRESS    = address;
                context.SaveChanges();
            }
            return(ShowCustomers());
        }