Пример #1
0
        public ActionResult Create([Bind(Include = "CategoryId,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "CategoryId,Name,DepartmentId")] Category category)
        {
            var loggedinuser = Session["courseshuffleloggedinuser"] as AppUser;

            if (ModelState.IsValid)
            {
                if ((loggedinuser != null) && (loggedinuser.Role == UserType.Administrator.ToString()))
                {
                    category.DateCreated      = DateTime.Now;
                    category.DateLastModified = DateTime.Now;
                    category.CreatedBy        = loggedinuser.AppUserId;
                    category.LastModifiedBy   = loggedinuser.AppUserId;
                    db.Categories.Add(category);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                TempData["category"]         = "A new category has been created!";
                TempData["notificationtype"] = NotificationType.Success.ToString();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", category.DepartmentId);
            return(View(category));
        }