Пример #1
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (VBSContext db = new VBSContext())
                {
                    var user = db.Users.AsQueryable().FirstOrDefault(a => a.ResetPasswordCode == model.ResetCode);
                    if (user != null)
                    {
                        user.Password          = GVBSHelpers.GVBSHelperClass.CreateMD5Password(model.NewPassword);
                        user.ResetPasswordCode = "";
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        ViewBag.SuccessMessage = "New password updated successfully.";
                    }
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Something invalid.";
            }

            return(View(model));
        }
Пример #2
0
 public override void Update()
 {
     Thread.Sleep(3000);
     System.Diagnostics.Debug.WriteLine(string.Format("kitap ebook ekleme başlıyor.... ID : {0}", EbookNo));
     try
     {
         string path = string.Format("~/Files/{0}/epub_{0}.epub", EbookNo);
         using (var fs = new FileStream(HostingEnvironment.MapPath(path), FileMode.Open))
         {
             EpubBook epubBook = EpubReader.ReadBook(fs);
             foreach (EpubTextContentFile textContentFile in epubBook.ReadingOrder)
             {
                 // HTML of current text content file
                 string htmlContent = textContentFile.Content;
                 HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                 htmlDocument.LoadHtml(htmlContent);
                 // Insert to db
                 using (VBSContext db = new VBSContext())
                 {
                     BookPage bp = new BookPage();
                     bp.BookId      = BookId;
                     bp.HtmlContent = htmlContent;
                     bp.Description = htmlDocument.DocumentNode.InnerText.Replace("\n", "<br/>");
                     db.BookPages.Add(bp);
                     db.SaveChanges();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.InnerException.Message);
     }
 }
Пример #3
0
 public ActionResult ForgotPassword(ForgotPasswordViewModel model)
 {
     if (ModelState.IsValid)
     {
         using (VBSContext db = new VBSContext())
         {
             var user = db.Users.AsQueryable().FirstOrDefault(u => u.Email == model.Email && u.IsAdmin == false);
             if (user == null)
             {
                 ViewBag.UserNotFound = "User didn't find in the system.";
             }
             else
             {
                 string resetCode = Guid.NewGuid().ToString();
                 GVBSHelpers.GVBSHelperClass.SendVerificationLinkEmail(model.Email, resetCode, "ResetPassword");
                 user.ResetPasswordCode = resetCode;
                 db.Configuration.ValidateOnSaveEnabled = false;
                 db.SaveChanges();
                 ViewBag.UserSendEmailSuccess = string.Format("Verification email was send your {0} email address.", model.Email);
             }
             return(View(model));
         }
     }
     return(View());
 }
Пример #4
0
        public ActionResult SoftDelete(int?id)
        {
            var LibraryId = id;

            using (VBSContext db = new VBSContext())
            {
                try
                {
                    Library library = db.Libraries.AsQueryable().FirstOrDefault(x => x.LibraryId == id);
                    if (library != null)
                    {
                        db.Configuration.AutoDetectChangesEnabled = true;
                        db.ChangeTracker.Entries();
                        library.DeletedAt = System.DateTime.Now;
                        db.SaveChanges();
                        TempData.Add("BookSoftDeleteSuccess", "Book was deleted successfully.");
                    }
                } catch (Exception ex)
                {
                    TempData.Add("BookSoftDeleteError", "Book was not deleted successfully.");
                }
            }

            return(RedirectToAction("Index", "MyLibrary"));
        }
Пример #5
0
        public ActionResult Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (VBSContext db = new VBSContext())
                {
                    var  password = GVBSHelpers.GVBSHelperClass.CreateMD5Password(model.Password);
                    User result   = db.Users.AsQueryable().FirstOrDefault(u => u.Email == model.Email && u.Password.Equals(password) && u.IsAdmin == false);
                    if (result == null)
                    {
                        model.Email          = null;
                        model.Password       = null;
                        ViewBag.UserNotFound = "Email Address and/or Password is incorrect.";
                        return(View(model));
                    }
                    CurrentSession.Set <User>("userLogin", result);

                    string redirectToBack = Session["RedirectToBack"] == null ? "" : Session["RedirectToBack"].ToString();
                    if (Session["RedirectToBack"] != null)
                    {
                        Session.Remove("RedirectToBack");
                        return(Redirect(redirectToBack));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            return(View());
        }
Пример #6
0
        public ActionResult Recovery(int?id)
        {
            var LibraryId = id;

            using (VBSContext db = new VBSContext())
            {
                try
                {
                    Library library = db.Libraries.AsQueryable().FirstOrDefault(x => x.LibraryId == id);
                    if (library != null)
                    {
                        db.Configuration.AutoDetectChangesEnabled = true;
                        db.ChangeTracker.Entries();
                        library.PageNumber = 0;
                        library.DeletedAt  = null;
                        db.SaveChanges();
                    }
                    TempData.Add("BookRecoverySuccess", "Book was recovery successfully.");
                }
                catch (Exception ex)
                {
                    TempData.Add("BookRecoveryError", "Book was not recovery successfully.");
                }
            }

            return(RedirectToAction("Index", "MyLibrary"));
        }
Пример #7
0
        // GET: MyLibrary
        public ActionResult Index()
        {
            LibraryViewModel myLib = new LibraryViewModel();

            using (VBSContext db = new VBSContext())
            {
                myLib.MySelectedBooks = db.Libraries
                                        .Include(s => s.Book)
                                        .Include(a => a.Book.Authors)
                                        .Include(c => c.Book.Categories)
                                        .Include(l => l.Book.Languages)
                                        .AsQueryable()
                                        .Where(x => x.UserId == CurrentSession.User.Id)
                                        .Where(d => d.DeletedAt.Equals(null))
                                        .ToList();

                myLib.MyDeletedSelectedBooks = db.Libraries
                                               .Include(s => s.Book)
                                               .Include(a => a.Book.Authors)
                                               .Include(c => c.Book.Categories)
                                               .Include(l => l.Book.Languages)
                                               .AsQueryable()
                                               .Where(x => x.UserId == CurrentSession.User.Id)
                                               .Where(d => !d.DeletedAt.Equals(null))
                                               .ToList();
            }
            return(View(myLib));
        }
Пример #8
0
 public static User GetUser(LoginViewModel model)
 {
     using (VBSContext db = new VBSContext())
     {
         return(db.Users.AsQueryable().FirstOrDefault(u => u.Email == model.Email && u.Password.Equals(model.Password) && u.IsAdmin == false));
     }
 }
Пример #9
0
        public ActionResult Profile(ProfileViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (VBSContext db = new VBSContext())
                {
                    try
                    {
                        User user = db.Users.AsQueryable().FirstOrDefault(c => c.Email == model.Email);
                        user.Name      = model.Name;
                        user.Surname   = model.Surname;
                        user.UpdatedAt = DateTime.Now;
                        db.SaveChanges();
                        TempData.Add("UserProfileSuccess", "User profile was update successfully.");
                    }
                    catch (Exception ex)
                    {
                        TempData.Add("UserProfileFail", "User profile was not update successfully.");
                    }

                    return(RedirectToAction("Profile", "Account"));
                }
            }
            return(View());
        }
Пример #10
0
        public BooksController(VBSContext context)
        {
            _context = context;

            if (_context.BookItems.Count() == 0)
            {
                // Populates a initial list of books
                CommonOperations.AddBooks(_context);
            }
        }
Пример #11
0
        public void Login_Failed_Method()
        {
            User user = null;

            using (VBSContext db = new VBSContext())
            {
                var email    = "*****@*****.**";
                var password = GVBSHelpers.GVBSHelperClass.CreateMD5Password("123456");
                user = db.Users.AsQueryable().FirstOrDefault(u => u.Email == email && u.Password.Equals(password) && u.IsAdmin == false);
            }

            Assert.IsNull(user);
        }
Пример #12
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (VBSContext db = new VBSContext())
                {
                    User control = db.Users.AsQueryable().FirstOrDefault(c => c.Email == model.Email);
                    // If user is not exists then save the user
                    if (control == null)
                    {
                        var  password = GVBSHelpers.GVBSHelperClass.CreateMD5Password(model.Password);
                        User user     = new User()
                        {
                            Name      = model.Name,
                            Surname   = model.Surname,
                            Email     = model.Email,
                            Password  = password,
                            IsAdmin   = false,
                            CreatedAt = DateTime.Now
                        };
                        db.Users.Add(user);
                        db.SaveChanges();
                        TempData["UserCreateSuccess"] = string.Format("Dear {0}, welcome to visual bookshelf.", model.Name + " " + model.Surname);

                        string redirectToBack = Session["RedirectToBack"] == null ? "" : Session["RedirectToBack"].ToString();
                        if (Session["RedirectToBack"] != null)
                        {
                            Session.Remove("RedirectToBack");
                            return(Redirect(redirectToBack));
                        }
                        else
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                    }
                    else
                    {
                        ViewBag.UserExists    = string.Format("User ({0}) is already exist in system.", model.Email);
                        model.Name            = null;
                        model.Surname         = null;
                        model.Email           = null;
                        model.Password        = null;
                        model.PasswordConfirm = null;
                        return(View(model));
                    }
                }
            }

            return(View());
        }
Пример #13
0
        public ActionResult Profile()
        {
            ProfileViewModel user = new ProfileViewModel();

            using (VBSContext db = new VBSContext())
            {
                User getUser = db.Users.AsQueryable().Where(x => x.Id == CurrentSession.User.Id).FirstOrDefault();
                user.Name    = getUser.Name;
                user.Surname = getUser.Surname;
                user.Email   = getUser.Email;
            }

            return(View(user));
        }
Пример #14
0
        /*Extracts book items from cart*/
        public async static Task <List <BookItem> > ExtractBooks(CartItem cart, VBSContext context)
        {
            var books = new List <BookItem>();

            foreach (var book in cart.BookItems)
            {
                var bookItem = await context.BookItems.FindAsync(book.BookId);

                if (bookItem == null)
                {
                    continue;
                }

                books.Add(bookItem);
            }

            return(books);
        }
Пример #15
0
        public ActionResult ReadBook(int?id, int?page)
        {
            ReadBookViewModel readBookViewModel = new ReadBookViewModel();

            using (VBSContext db = new VBSContext())
            {
                // Library
                Library library = db.Libraries
                                  .Include(s => s.Book)
                                  .Include(a => a.Book.Authors)
                                  .Include(c => c.Book.Categories)
                                  .Include(l => l.Book.Languages)
                                  .AsQueryable()
                                  .FirstOrDefault(x => x.LibraryId == id);

                readBookViewModel.LibraryDetail = library;

                library.PageNumber = Convert.ToInt32(page);
                db.SaveChanges();

                int bookPageCount = db.BookPages.AsQueryable().Where(x => x.BookId == library.BookId).Count();
                int pageNumber    = 0;

                int firstIndex = db.BookPages.AsQueryable().Where(x => x.BookId == library.BookId).FirstOrDefault().BookPageId;

                if (page > bookPageCount)
                {
                    pageNumber = (Convert.ToInt32(firstIndex) + Convert.ToInt32(bookPageCount)) - 1;
                }
                else
                {
                    pageNumber = (page == 1 ? firstIndex : (Convert.ToInt32(firstIndex) + Convert.ToInt32(page)));
                }

                BookPage bookPage = db.BookPages
                                    .AsQueryable()
                                    .Where(x => x.BookId == library.BookId)
                                    .Where(y => y.BookPageId == pageNumber)
                                    .FirstOrDefault();

                readBookViewModel.BookPages = bookPage;
            }
            return(View(readBookViewModel));
        }
Пример #16
0
        public ActionResult Delete(int?id)
        {
            var LibraryId = id;

            using (VBSContext db = new VBSContext())
            {
                try
                {
                    Library library = db.Libraries.AsQueryable().FirstOrDefault(x => x.LibraryId == id);
                    db.Libraries.Remove(library);
                    db.SaveChanges();
                    TempData.Add("BookDeleteSuccess", "Book was deleted successfully.");
                }
                catch (Exception ex)
                {
                    TempData.Add("BookDeleteError", "Book was not deleted successfully.");
                }
            }

            return(RedirectToAction("Index", "MyLibrary"));
        }
Пример #17
0
        public ActionResult ResetPassword(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(HttpNotFound());
            }

            using (VBSContext db = new VBSContext())
            {
                var user = db.Users.AsQueryable().FirstOrDefault(a => a.ResetPasswordCode == id);
                if (user != null)
                {
                    ResetPasswordModel model = new ResetPasswordModel();
                    model.ResetCode = id;
                    return(View(model));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
        }
Пример #18
0
        /*Populates book items*/
        public static void AddBooks(VBSContext context)
        {
            var isbn   = "123456";
            var title  = "This is the title of book #";
            var genres = new List <string>()
            {
                "male", "female"
            };
            var synopsis = "This book is the book #";
            var value    = 20;

            var books      = new List <BookItem>();
            var pagination = new PaginationItem();

            pagination.Limit  = 40;
            pagination.Offset = 20;
            pagination.Total  = 1000;

            for (int i = 0; i < 10; i++)
            {
                // Select the genre according to current index
                var index = (i % 2) == 0? 0 : 1;

                BookItem book = new BookItem()
                {
                    Isbn       = isbn + i,
                    Title      = title + i,
                    Genre      = genres[index],
                    Synopsis   = synopsis + i,
                    Value      = (long)value / (i + 1),
                    Pagination = pagination
                };

                context.BookItems.Add(book);
            }

            context.SaveChanges();
        }
Пример #19
0
        public ActionResult Create(int BookId, int EbookNo)
        {
            var userId = CurrentSession.User.Id;

            using (VBSContext db = new VBSContext())
            {
                Book getBook     = db.Books.AsQueryable().Where(b => b.EbookNo == EbookNo).FirstOrDefault();
                var  bookControl = db.Libraries.AsQueryable().Where(x => x.BookId == BookId && x.UserId == userId).FirstOrDefault();

                if (bookControl == null)
                {
                    Library newLibrary = new Library()
                    {
                        BookId     = BookId,
                        UserId     = userId,
                        PageNumber = 0,
                        CreatedAt  = System.DateTime.Now,
                        Book       = getBook
                    };

                    List <Author>   getAuthors    = getBook.Authors.ToList();
                    List <Category> getCategories = getBook.Categories.ToList();
                    List <Language> getLanguages  = getBook.Languages.ToList();

                    newLibrary.Book.Authors    = getAuthors;
                    newLibrary.Book.Categories = getCategories;
                    newLibrary.Book.Languages  = getLanguages;
                    db.Libraries.Add(newLibrary);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "MyLibrary"));
                }
                else
                {
                    TempData.Add("EbookExistInLibrary", "This book has already exist in your library.");
                    return(RedirectToAction("View", "Ebooks", new { id = EbookNo }));
                }
            }
        }
Пример #20
0
        /*Extracts order items from delivery*/
        public async static Task <List <OrderItem> > ExtractOrders(DeliveryItem delivery, VBSContext context)
        {
            var orders = new List <OrderItem>();

            foreach (var order in delivery.OrderItems)
            {
                var orderItem = await context.OrderItems.FindAsync(order.OrderId);

                if (orderItem == null)
                {
                    continue;
                }

                orders.Add(orderItem);
            }

            return(orders);
        }
Пример #21
0
 public OrdersController(VBSContext context)
 {
     _context = context;
 }
Пример #22
0
 /// <summary>
 /// Author Thread Method
 /// </summary>
 /// <param name="authorResults"></param>
 private void BookSaveThreadMethod(SearchResult book)
 {
     try
     {
         HashSet <Author>   authors    = new HashSet <Author>();
         HashSet <Category> categories = new HashSet <Category>();
         HashSet <Language> languages  = new HashSet <Language>();
         // Download Files
         if (!Directory.Exists(Server.MapPath("~/Files/" + book.Id)))
         {
             Directory.CreateDirectory(Server.MapPath("~/Files/" + book.Id));
         }
         string imageUrl    = string.Format("http://www.gutenberg.org/files/{0}/{0}-h/images/cover.jpg", book.Id);
         string epubUrl     = string.Format("http://www.gutenberg.org/ebooks/{0}.epub.images", book.Id);
         string newImageUrl = null;
         string newEpubUrl  = null;
         // Download Image
         try
         {
             WebClient wcImage = new WebClient();
             wcImage.DownloadFile(imageUrl, Server.MapPath("~/Files/" + book.Id + "/" + ("cover_" + book.Id + ".jpg")));
             newImageUrl = "/Files/" + book.Id + "/" + ("cover_" + book.Id + ".jpg");
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine("############# book image error #############" + ex.Message);
         }
         // Download Epub
         try
         {
             WebClient wcEpub = new WebClient();
             wcEpub.DownloadFile(epubUrl, Server.MapPath("~/Files/" + book.Id + "/" + ("epub_" + book.Id + ".epub")));
             newEpubUrl = "/Files/" + book.Id + "/" + ("epub_" + book.Id + ".epub");
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine("############# book epub error #############" + ex.Message);
         }
         // Book Save
         using (VBSContext db = new VBSContext())
         {
             // Authors
             foreach (AuthorResult ar in book.Authors)
             {
                 Author author = db.Authors.AsQueryable().Where(a => a.AuthorName == ar.Name).FirstOrDefault();
                 if (author == null)
                 {
                     Author newAuthor = new Author()
                     {
                         AuthorName = ar.Name,
                         BirthYear  = ar.Birth_year,
                         DeathYear  = ar.Death_year,
                         CreatedAt  = DateTime.Now
                     };
                     db.Authors.Add(newAuthor);
                     authors.Add(newAuthor);
                 }
                 else
                 {
                     authors.Add(author);
                 }
             }
             // Categories
             foreach (var c in book.Subjects)
             {
                 Category category = db.Categories.AsQueryable().Where(mc => mc.CategoryTitle == c).FirstOrDefault();
                 if (category == null)
                 {
                     Category newCategory = new Category()
                     {
                         CategoryTitle = c,
                         CreatedAt     = DateTime.Now
                     };
                     db.Categories.Add(newCategory);
                     categories.Add(newCategory);
                 }
                 else
                 {
                     categories.Add(category);
                 }
             }
             // Languages
             foreach (var lang in book.Languages)
             {
                 Language language = db.Languages.AsQueryable().Where(ml => ml.LanguageCode == lang).FirstOrDefault();
                 if (language == null)
                 {
                     Language newLanguage = new Language()
                     {
                         LanguageTitle = GVBSHelpers.GVBSHelperClass.ConvertLanguage(lang),
                         LanguageCode  = lang,
                         CreatedAt     = DateTime.Now
                     };
                     db.Languages.Add(newLanguage);
                     languages.Add(newLanguage);
                 }
                 else
                 {
                     languages.Add(language);
                 }
             }
             // new book
             Book newBook = new Book()
             {
                 BookTitle       = book.Title,
                 EbookNo         = book.Id,
                 BookContents    = "",
                 FileName        = newImageUrl,
                 FileEpub        = newEpubUrl,
                 MediaType       = book.Media_type,
                 DownloadCount   = book.Download_count,
                 Price           = 0,
                 CopyrightStatus = book.Copyright,
                 Authors         = authors,
                 Categories      = categories,
                 Languages       = languages,
                 CreatedAt       = DateTime.Now
             };
             db.Books.Add(newBook);
             db.SaveChanges();
             // Detail
             Book getBookDetail = db.Books.AsQueryable().FirstOrDefault(x => x.EbookNo == book.Id);
             if (getBookDetail != null)
             {
                 getBookDetail.Attach(new EbookObserver(book.Id, getBookDetail.BookId));
                 getBookDetail.Notify();
                 //db.SaveChanges();
             }
         }
     } catch (DbEntityValidationException ex)
     {
         System.Diagnostics.Debug.WriteLine(string.Format("############# book error : {0} #############", ex.Message));
     } catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(string.Format("############# book error : {0} #############", ex.Message));
     }
 }
Пример #23
0
 public ReviewsController(VBSContext context)
 {
     _context = context;
 }
Пример #24
0
 public DeliveriesController(VBSContext context)
 {
     _context = context;
 }
Пример #25
0
 public CartsController(VBSContext context)
 {
     _context = context;
 }