Ejemplo n.º 1
0
        // POST: UserProfiles/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        private ActionResult EditUserProfile(UserProfile userProfile, string[] Roles, string ReturnUrl)
        {
            //isLoginIsAvailable(userProfile.UserName);

            if (ModelState.IsValid)
            {
                db.Entry(userProfile).State = EntityState.Modified;

                if (User.IsInRole("Admin"))
                {
                    RemoveUserFromRoles(userProfile.UserName);
                    AddUserToRoles(userProfile.UserName, Roles);
                }

                db.SaveChanges();

                //if (User.IsInRole("Admin"))
                //{
                //	return RedirectToAction("Index");
                //	/*Redirect(Request.UrlReferrer.ToString());*/
                //}
                return(Redirect(ReturnUrl));
            }
            else
            {
                return(View("Edit", new UserProfileFull(userProfile)));
            }
        }
        public ActionResult Create([Bind(Include = "UserId,UserName,FirstName,LastName,Patronymic,Email")] UserProfile userProfile)
        {
            if (ModelState.IsValid)
            {
                db.UserProfiles.Add(userProfile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userProfile));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ProductId")] Order order)
        {
            if (!WebSecurity.IsAuthenticated)
            {
                return(RedirectToAction("Register", "Account"));
            }

            Product orderedProduct = Utility.GetProductById(db, order.ProductId);

            if (orderedProduct.Count < 1)
            {
                return(View());
            }

            int productsOrderedCount = 1;

            order.UserId = WebSecurity.GetUserId(User.Identity.Name);

            //ViewBag.UserId = Utility.UsersIdSelectList(order.UserId);
            //ViewBag.ProductId = Utility.ProductsIdSelectList(order.ProductId);

            Order orderInDb = Utility.GetOrderByProductIdAndUserId(db, order.ProductId, order.UserId);

            if (orderInDb == null)
            {
                if (ModelState.IsValid)
                {
                    order.Date   = DateTime.Now;
                    order.Count += productsOrderedCount;
                    db.Orders.Add(order);
                    db.SaveChanges();
                }
            }
            else
            {
                if (orderInDb.Count + productsOrderedCount > orderedProduct.Count)
                {
                    AddModalError_ProductCountOnStorage(orderInDb.Count);
                }
                if (ModelState.IsValid)
                {
                    orderInDb.Count          += productsOrderedCount;
                    orderInDb.Date            = DateTime.Now;
                    db.Entry(orderInDb).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("OrdersUser"));
        }
        public ActionResult Create([Bind(Include = "CustomerId,Name,Email")] Customer customer)
        {
            isLoginIsAvailable(customer.Name);

            //if (customer.Email != null && !new Regex(@"\b[a-z0-9._]+@[a-z0-9.-]+\.[a-z]{2,4}\b").IsMatch(customer.Email))
            //{
            //	ModelState.AddModelError("Email", "Email не правильный");
            //}
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "ProductId,Name,Description,Price,Category,Count")] Product product, HttpPostedFileBase file)
        {
            /*ViewBag.Category = */
            ViewBag.Categories = Utility.CategoriesSelectList();
            if (product.Category == "all")
            {
                ModelState.AddModelError("Category", "Выберите категорию продукта");
            }
            if (ModelState.IsValid)
            {
                product.imgName = ImageFuctionality.UploadImage(file, Server.MapPath("~"), ImageFuctionality.imagesDirectoryPath);
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }