Esempio n. 1
0
        public ActionResult Create(string Title_Text, string Description, int Page_ID)
        {
            string         libName      = Title_Text.Replace(" ", "");
            List <Library> existingLibs = (List <Library>)(from l in db.Libraries where l.Library_Name == libName select l).ToList();

            if (!(existingLibs.Count() > 0))
            {
                Library library = new Library();
                library.Title_Text   = Title_Text;
                library.Library_Name = libName;
                library.Description  = Description;
                library.Date_Added   = DateTime.Now;
                library.Added_By     = User.Identity.Name.ToString();///TODO: auth needed
                library.Archived     = false;
                db.Libraries.Add(library);
                db.SaveChanges();

                PageLibraryAssign libAss = new PageLibraryAssign();
                libAss.Library = library;
                libAss.Page_ID = Page_ID;
                db.PageLibraryAssigns.Add(libAss);
                db.SaveChanges();

                return(RedirectToAction("Edit", new { Page_ID = Page_ID, Library_ID = library.Library_ID }));
            }
            else
            {
                ModelState.AddModelError("", "A Library with the name '" + Title_Text + "' already exists");
                LibraryCreateViewModel libMod = new LibraryCreateViewModel();
                libMod.Page_ID     = Page_ID;
                libMod.Description = Description;
                libMod.Title_Text  = Title_Text;
                return(View(libMod));
            }
        }
Esempio n. 2
0
        public ActionResult RemoveLibrary(int Page_ID, int Library_ID)
        {
            PageLibraryAssign lib = (PageLibraryAssign)db.PageLibraryAssigns.Where(x => x.Library_ID == Library_ID && x.Page_ID == Page_ID).FirstOrDefault();

            if (lib == null)
            {
                return(HttpNotFound());
            }
            lib.Archive_By   = User.Identity.Name.ToString();///TODO: auth
            lib.Date_Archive = DateTime.Now;
            lib.Archived     = true;
            db.SaveChanges();
            return(RedirectToAction("Edit", new { id = Page_ID }));
        }