예제 #1
0
        public ActionResult Index(Module module)
        {
            module.Department = User.Identity.Name; // set department automatically

            if (module.ModuleCode == null || module.ModuleTitle == null)
            {
                //return RedirectToAction("Index");
                //return CreateForm(new Module());    // triggers IEnumerable error
            }

            module.Department = module.Department;

            if (ModelState.IsValid)
            {
                bool moduleExists = true;  // check if module already exists
                foreach (var item in systemDB.Modules)
                {
                    if (item.ModuleCode == module.ModuleCode)
                    {
                        moduleExists = false;
                    }
                }

                if (moduleExists == false)
                {
                    Module temp = systemDB.Modules.Find(module.ModuleCode);    // remove duplicate
                    systemDB.Entry(temp).State = System.Data.EntityState.Deleted;
                }
                systemDB.Modules.Add(module);
                systemDB.SaveChanges();
                return(RedirectToAction("Index", "Module", new { moduleCode = " " }));  // if successful, return to the list of modules
            }
            return(RedirectToAction("Index", "Module", new { moduleCode = " " }));
            //return CreateForm(module);  // if unsuccessful, provide the filled out form again
        }
        public ActionResult Index(Request request)
        {
            request = this.processRequest(request);

            if (ModelState.IsValid)
            {
                db.Requests.Add(request);
                db.SaveChanges();
                ViewBag.Message = "Request Created";

                return(CreateForm(new Request()));
            }

            return(CreateForm(request));
        }