示例#1
0
        public ActionResult Create([Bind(Include = "id,name")] category category)
        {
            if (ModelState.IsValid)
            {
                db.categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public ActionResult Create([Bind(Include = "id,name,surname,age,email,phone")] User_reg user_reg)
        {
            if (ModelState.IsValid)
            {
                db.User_reg.Add(user_reg);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user_reg));
        }
示例#3
0
        public ActionResult Create([Bind(Include = "id,category_name,photo,title,author,dates,text,pages,type_id,categoryID")] C_News_category c_News_category)
        {
            if (ModelState.IsValid)
            {
                db.C_News_category.Add(c_News_category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.categoryID = new SelectList(db.categories, "id", "name", c_News_category.categoryID);
            ViewBag.type_id    = new SelectList(db.types, "id", "name", c_News_category.type_id);
            return(View(c_News_category));
        }
示例#4
0
        public ActionResult Registr(Registr reg)
        {
            if (ModelState.IsValid)
            {
                using (watcherEntities data = new watcherEntities())
                {
                    var EmailRepeating = data.User_reg.Where(x => x.email == reg.email).ToList();
                    if (EmailRepeating.Count > 0)
                    {
                        ModelState.AddModelError("Repeat", "This email has already exist,please change this email");
                    }
                    User_reg user = new User_reg();
                    user.name     = reg.name;
                    user.surname  = reg.surname;
                    user.age      = reg.age;
                    user.email    = reg.email;
                    user.phone    = reg.phone;
                    user.password = reg.password;
                    data.User_reg.Add(user);
                    data.SaveChanges();

                    Response.Write("<script>alert(Success,Registration successfully done.)</script>");
                }
            }
            return(View());
        }
示例#5
0
        public ActionResult Create([Bind(Exclude = "file_path")] HttpPostedFileBase file_path, Models.File file)
        {
            Models.File newFile = new Models.File();
            if (ModelState.IsValid)
            {
                if (file_path.ContentLength > 0)

                {
                    var file_extention = Path.GetExtension(file_path.FileName);
                    var file_new_name  = file.file_name + file_extention;
                    var file_src       = Path.Combine(Server.MapPath("~/Public/"), file_new_name);
                    file_path.SaveAs(file_src);
                    newFile.file_name = file_new_name;
                    newFile.file_type = MimeMapping.GetMimeMapping(file_path.FileName);
                    newFile.file_size = file_path.ContentLength.ToString();
                    newFile.file_path = "/Public/" + file_new_name;
                }
                db.Files.Add(newFile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(newFile));
        }