コード例 #1
0
        public ActionResult Create(int Page_ID, bool?Return_Home)
        {
            CalenderCreateViewModel calViewMod = new CalenderCreateViewModel(Page_ID);

            if (Return_Home != null)
            {
                ViewBag.Return_Home = true;
                Page page = db.Pages.Find(Page_ID);
                ViewBag.Page_Url = page.URL;
            }
            return(View(calViewMod));
        }
コード例 #2
0
        public ActionResult Create(string Calender_Name, int Page_ID, bool?Return_Home)
        {
            if (Return_Home != null)
            {
                ViewBag.Return_Home = true;
                Page page = db.Pages.Find(Page_ID);
                ViewBag.Page_Url = page.URL;
            }
            if (db.Calenders.Where(x => x.Calender_Name == Calender_Name).Count() > 0)
            {
                CalenderCreateViewModel calViewMod = new CalenderCreateViewModel(Page_ID);
                calViewMod.Calender_Name = Calender_Name;
                ModelState.AddModelError("", "A Calender with the name '" + Calender_Name + "' alredy exists.");
                return(View(calViewMod));
            }
            else
            {
                Calender cal = new Calender();
                cal.Calender_Name = Calender_Name;
                cal.Date_Added    = DateTime.Now;
                cal.Added_By      = User.Identity.Name.ToString();///TODO: auth
                cal.Archived      = false;
                db.Calenders.Add(cal);
                db.SaveChanges();

                PageCalenderAssign callAss = new PageCalenderAssign();
                callAss.Page_ID    = Page_ID;
                callAss.Calender   = cal;
                callAss.Archived   = false;
                callAss.Date_Added = DateTime.Now;
                callAss.Added_By   = User.Identity.Name.ToString();///TODO: auth
                db.PageCalenderAssigns.Add(callAss);
                db.SaveChanges();

                return(RedirectToAction("Edit", new { Page_ID = Page_ID, Calender_ID = cal.Calender_ID, Return_Home = Return_Home }));
            }
        }