Esempio n. 1
0
        public ActionResult MakeOrder(RegistrationVM model)
        {
            string productsId = Session["OrderProduct"].ToString();
            string quantities = Session["ProductQuantity"].ToString();
            string userID     = Session["User_ID"].ToString();

            string[] keyProduct  = productsId.Split(',');
            string[] keyQuantity = quantities.Split(',');

            User        user  = new User();
            UserServise _user = new UserServise();

            if (userID != null)
            {
                EncriptServises _encript = new EncriptServises();
                for (int i = 0; i < keyProduct.Length - 1; i++)
                {
                    Order entity = new Order();
                    entity.SubjectID   = int.Parse(keyProduct[i]);
                    entity.Quantity    = int.Parse(keyQuantity[i]);
                    entity.OrderNumber = Session["OrderNumber"].ToString();
                    entity.Date        = DateTime.Today.ToString("dd/MM/yyyy");
                    entity.Status      = Status.Supplier;

                    Product element = _product.GetByID(entity.SubjectID);
                    entity.Total = (entity.Quantity * element.Price);
                    _order.Save(entity);
                    entity.UserID = int.Parse(userID);
                    _order.Save(entity);


                    ChangewquantityOfPRoduct(element, entity.Quantity);
                }
            }
            else
            {
                user = AddUserInDB(user, model);
                _user.Save(user);
                user = new User();
                for (int i = 0; i < keyProduct.Length - 1; i++)
                {
                    Order entity = new Order();
                    entity.SubjectID   = int.Parse(keyProduct[i]);
                    entity.Quantity    = int.Parse(keyQuantity[i]);
                    entity.OrderNumber = Session["OrderNumber"].ToString();
                    entity.Date        = DateTime.Today.ToString("dd/MM/yyyy");
                    entity.Status      = Status.Supplier;
                    user          = _user.GetLastElement();
                    entity.UserID = user.ID;

                    Product element = _product.GetByID(entity.SubjectID);

                    entity.Total = (entity.Quantity * element.Price);
                    _order.Save(entity);
                    ChangewquantityOfPRoduct(element, entity.Quantity);
                }
            }
            DeleteSession();
            return(RedirectToAction("CungratOrder"));
        }
        public IActionResult ChangeDetails(UserEditVm model, IFormFile[] photo)
        {
            User entity = new User();

            entity.ID         = UserID;
            entity.Name       = _encript.EncryptData(model.FirstName);
            entity.SecondName = _encript.EncryptData(model.SecondName);
            entity.City       = _encript.EncryptData(model.City);
            entity.Adress     = _encript.EncryptData(model.Adress);
            entity.Telephone  = _encript.EncryptData(model.Telephone);
            entity.Image      = GetImagePath(photo);
            entity.LoginID    = loginID;
            Addimage(photo);

            _servise.Save(entity);

            return(RedirectToAction("Details"));
        }
        private User AddUSerINformation(RegistrationVM reg)
        {
            List <Login> list = new List <Login>();

            list = _servise.GetAll(x => x.Email == _encript.EncryptData(reg.Email));
            User user = new User();

            user.LoginID    = list[0].ID;
            user.Name       = _encript.EncryptData(reg.FirstName);
            user.SecondName = _encript.EncryptData(reg.SecondName);
            user.City       = _encript.EncryptData(reg.City);
            user.Adress     = _encript.EncryptData(reg.Adress);
            user.Telephone  = _encript.EncryptData(reg.Telephone);
            user.Image      = "../images/userIcon.png";
            UserServise _userServise = new UserServise();

            _userServise.Save(user);
            return(user);
        }