예제 #1
0
        public ActionResult ApproveAuthor(int id)
        {
            try
            {
                var profile = (UserProfile)Session["UserInfo"];
                if (profile == null || profile.Role == RolesCustom.USER)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                using (var db = new SDCContext())
                {
                    var author = db.Authors.Find(id);
                    author.IsVerified     = true;
                    author.LastModifiedBy = db.AttachProfile(profile);
                    db.SaveChanges();
                }

                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public ActionResult UpdateBook(BookViewModel bookViewModel)
        {
            var profile = ((UserProfile)Session["UserInfo"]);

            if (!User.Identity.IsAuthenticated || profile == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            try
            {
                using (var db = new SDCContext())
                {
                    db.AttachProfile(profile);

                    var book = db.Books
                               .Include(b => b.Authors)
                               .Include(b => b.Genres)
                               .Include(b => b.Publisher)
                               .Include(b => b.Language)
                               .Include(b => b.Shelf)
                               .First(b => b.Id == bookViewModel.Id);

                    AutoMapper.Mapper.Map <BookViewModel, Book>(bookViewModel, book);

                    Book.MapComplexProperties(db, book, bookViewModel, profile);

                    db.SaveChanges();

                    //activity
                    SDC.Library.Helpers.ActivityHelper.Activity_BookUpdated(
                        db, profile, book,
                        Url.Action("ViewBook", "Book", new { id = book.Id }),
                        Url.Action("Details", "Shelves", new { id = book.Shelf.Id }));

                    return(new HttpStatusCodeResult(HttpStatusCode.OK));
                }
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
예제 #3
0
        public JsonResult AddBook(BookViewModel bookViewModel)
        {
            var profile = (UserProfile)Session["UserInfo"];

            if (!User.Identity.IsAuthenticated || profile == null)
            {
                //STUPID
                return(Json(new { id = -1 }));
            }

            int id = 0;

            using (var db = new SDCContext())
            {
                db.AttachProfile(profile);

                //verify that the shelf exists and it belongs to the logged in user
                var shelf = db.Shelves.Include(o => o.Owner).FirstOrDefault(s => s.Id == bookViewModel.ShelfId);
                if (shelf == null || shelf.Owner.UserId != profile.UserId)
                {
                    //STUPID
                    return(Json(new { id = -1 }));
                }

                Book book = AutoMapper.Mapper.Map <Book>(bookViewModel);
                book.Shelf     = shelf;
                book.AddedDate = DateTime.Now;
                Book.MapComplexProperties(db, book, bookViewModel, profile);

                db.Books.Add(book);
                db.SaveChanges();
                id = book.Id;

                //activity
                SDC.Library.Helpers.ActivityHelper.Activity_BookAdded(
                    db, profile, book,
                    Url.Action("ViewBook", "Book", new { id = book.Id }),
                    Url.Action("Details", "Shelves", new { id = book.Shelf.Id }));
            }

            return(Json(new { id = id }));
        }
예제 #4
0
        public JsonResult AddBook(BookViewModel bookViewModel)
        {
            var profile = (UserProfile)Session["UserInfo"];
            if (!User.Identity.IsAuthenticated || profile == null)
            {
                //STUPID
                return Json(new { id = -1 });
            }

            int id = 0;

            using (var db = new SDCContext())
            {
                db.AttachProfile(profile);

                //verify that the shelf exists and it belongs to the logged in user
                var shelf = db.Shelves.Include(o => o.Owner).FirstOrDefault(s => s.Id == bookViewModel.ShelfId);
                if (shelf == null || shelf.Owner.UserId != profile.UserId)
                {
                    //STUPID
                    return Json(new { id = -1 });
                }

                Book book = AutoMapper.Mapper.Map<Book>(bookViewModel);
                book.Shelf = shelf;
                book.AddedDate = DateTime.Now;
                Book.MapComplexProperties(db, book, bookViewModel, profile);

                db.Books.Add(book);
                db.SaveChanges();
                id = book.Id;

                //activity
                SDC.Library.Helpers.ActivityHelper.Activity_BookAdded(
                    db, profile, book,
                    Url.Action("ViewBook", "Book", new { id = book.Id }),
                    Url.Action("Details", "Shelves", new { id = book.Shelf.Id }));
            }

            return Json(new { id = id });
        }
예제 #5
0
        public ActionResult ApproveAuthor(int id)
        {
            try
            {
                var profile = (UserProfile)Session["UserInfo"];
                if (profile == null || profile.Role == RolesCustom.USER)
                    return RedirectToAction("Index", "Home");

                using (var db = new SDCContext())
                {
                    var author = db.Authors.Find(id);
                    author.IsVerified = true;
                    author.LastModifiedBy = db.AttachProfile(profile);
                    db.SaveChanges();
                }

                return new HttpStatusCodeResult(HttpStatusCode.OK);
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
예제 #6
0
        public ActionResult UpdateBook(BookViewModel bookViewModel)
        {
            var profile = ((UserProfile)Session["UserInfo"]);
            if (!User.Identity.IsAuthenticated || profile == null)
                return RedirectToAction("Index", "Home");

            try
            {
                using (var db = new SDCContext())
                {
                    db.AttachProfile(profile);

                    var book = db.Books
                        .Include(b=>b.Authors)
                        .Include(b=>b.Genres)
                        .Include(b=>b.Publisher)
                        .Include(b=>b.Language)
                        .Include(b=>b.Shelf)
                        .First(b => b.Id == bookViewModel.Id);

                    AutoMapper.Mapper.Map<BookViewModel, Book>(bookViewModel, book);

                    Book.MapComplexProperties(db, book, bookViewModel, profile);

                    db.SaveChanges();

                    //activity
                    SDC.Library.Helpers.ActivityHelper.Activity_BookUpdated(
                        db, profile, book,
                        Url.Action("ViewBook", "Book", new { id = book.Id }),
                        Url.Action("Details", "Shelves", new { id = book.Shelf.Id }));

                    return new HttpStatusCodeResult(HttpStatusCode.OK);
                }
            }
            catch(Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
            }
        }