Ejemplo n.º 1
0
        public virtual ActionResult Create(CreateViewModel user)
        {
            string username = user.Name.Trim();

            if (string.Compare(username, "AdminAdmin") == 0)
            {
                ModelState.AddModelError(key: "Name", errorMessage: "Some error message!");
            }
            if (username.Length < 7)
            {
                ModelState.AddModelError(key: "Name", errorMessage: "نام کاربری باید بیش از هشت حروف باشد");
            }

            if (ModelState.IsValid)
            {
                User objUser = new User();

                objUser.Mobile     = user.Mobile;
                objUser.Address    = user.Address;
                objUser.Name       = username;
                objUser.Password   = oHash.GetCreateHash(user.Password);
                objUser.DataCreate = DateTime.Now;
                MyUnitOfWork.UserRepository.Insert(objUser);
                MyUnitOfWork.Save();
                //db.Users.Add(user);
                //db.SaveChanges();
                return(RedirectToAction(MVC.Account.Login()));
            }
            return(View(user));
        }
Ejemplo n.º 2
0
        public virtual ActionResult Create(Product product, HttpPostedFileBase file)
        {
            if (file == null)
            {
                ModelState.AddModelError(key: "Available", errorMessage: "انتخاب عکس اجباری می باشد");
            }
            if (ModelState.IsValid)
            {
                var allowedExtensions = new[] { ".Jpg", ".png", ".jpg", "jpeg" };

                var fileName = Path.GetFileName(file.FileName);
                var ext      = Path.GetExtension(file.FileName);

                if (allowedExtensions.Contains(ext))
                {
                    string name   = Path.GetFileNameWithoutExtension(fileName);
                    string myfile = name + "_" + product.Name + ext;
                    var    path   = Path.Combine(Server.MapPath("~/Picture"), myfile);
                    product.Image_url = "/Picture/" + myfile;
                    file.SaveAs(path);
                }

                MyUnitOfWork.ProductRepository.Insert(product);
                MyUnitOfWork.Save();
                return(RedirectToAction(MVC.Order.Index()));
            }

            return(View(product));
        }
Ejemplo n.º 3
0
        public virtual ActionResult DeleteConfirmed(int id)
        {
            Product product = MyUnitOfWork.ProductRepository.GetById(id);

            MyUnitOfWork.ProductRepository.Delete(product);
            MyUnitOfWork.Save();
            return(RedirectToAction("Index"));
        }
        public virtual ActionResult Create([Bind(Include = "Id,Name")] UnitProduct unitProduct)
        {
            if (ModelState.IsValid)
            {
                MyUnitOfWork.UnitProductRepository.Insert(unitProduct);
                MyUnitOfWork.Save();
                return(RedirectToAction("Index"));
            }

            return(View(unitProduct));
        }
Ejemplo n.º 5
0
        public virtual ActionResult Edit([Bind(Include = "Id,Name,Price,Weight,UnitProductId")] Product product)
        {
            if (ModelState.IsValid)
            {
                MyUnitOfWork.ProductRepository.Update(product);
                MyUnitOfWork.Save();

                return(RedirectToAction("Index"));
            }
            ViewBag.UnitProductId = new SelectList(db.UnitProducts, "Id", "Name", product.UnitProductId);
            return(View(product));
        }
Ejemplo n.º 6
0
        public virtual ActionResult Create([Bind(Include = "Id,Name,Price,Weight,UnitProductId")] Product product)
        {
            if (ModelState.IsValid)
            {
                MyUnitOfWork.ProductRepository.Insert(product);
                MyUnitOfWork.Save();

                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Ejemplo n.º 7
0
        public virtual ActionResult Create(User user)
        {
            if (string.Compare(user.Name, "Hjalalat") == 0)
            {
                ModelState.AddModelError(key: "Name", errorMessage: "Some error message!");
            }

            if (ModelState.IsValid)
            {
                Hash oHash = new Hash();
                user.Password   = oHash.GetCreateHash(user.Password);
                user.DataCreate = DateTime.Now;
                MyUnitOfWork.UserRepository.Insert(user);
                MyUnitOfWork.Save();
                //db.Users.Add(user);
                //db.SaveChanges();
                return(RedirectToAction(MVC.Users.Index()));
            }
            return(View(user));
        }