Ejemplo n.º 1
0
        public SelectList GetAuthorSelectList(int Bookid)
        {
            var context = new BookStoreEntities();
            var result  = from a in context.Author
                          join r in context.BookAuthor
                          on a.Id equals r.AuthorId
                          where r.BookId == Bookid
                          orderby FullName                          // not sure this works here (see above)
                          select new AuthorSelectList()
            {
                Id       = a.Id,
                FullName = a.LastName + ", " + a.FirstName
            };

            var selectListItems = new List <SelectListItem>();

            foreach (var item in result)
            {
                var selectListItem = new SelectListItem
                {
                    Text  = item.FullName,
                    Value = item.Id.ToString()
                };

                selectListItems.Add(selectListItem);
            }

            var authorSelectList = new SelectList(
                selectListItems, "Value", "Text");

            return(authorSelectList);
        }
Ejemplo n.º 2
0
        // Update
        public bool UpdateAuthor(int id, AuthorModel author)
        {
            using (BookStoreEntities ef = new BookStoreEntities())
            {
                Author updatedAuthor = ef.Authors.FirstOrDefault(a => a.AuthorID == id);
                if (updatedAuthor == null)
                {
                    return(false);
                }

                updatedAuthor.AuthorAge   = author.AuthorAge;
                updatedAuthor.AuthorName  = author.AuthorName;
                updatedAuthor.AuthorImage = author.AuthorImage;

                try
                {
                    ef.SaveChanges();
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        // Read
        public List <BookModel> GetAllBooks()
        {
            List <BookModel> books = new List <BookModel>();

            using (BookStoreEntities ef = new BookStoreEntities())
            {
                foreach (Book item in ef.Books)
                {
                    books.Add(
                        new BookModel()
                    {
                        BookName   = item.BookName,
                        BookPrice  = item.BookPrice,
                        BookAuthor = new AuthorModel()
                        {
                            AuthorAge   = item.Author.AuthorAge,
                            AuthorName  = item.Author.AuthorName,
                            AuthorImage = item.Author.AuthorImage
                        }
                    }

                        );
                }
            }
            return(books);
        }
Ejemplo n.º 4
0
        // Update
        public bool UpdateBook(int id, BookModel book)
        {
            using (BookStoreEntities ef = new BookStoreEntities())
            {
                Book updatedBook = ef.Books.FirstOrDefault(b => b.BookID == id);
                if (updatedBook == null)
                {
                    return(false);
                }

                updatedBook.BookName  = book.BookName;
                updatedBook.BookPrice = book.BookPrice;

                try
                {
                    ef.SaveChanges();
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        private void BindGrid()
        {
            BookStoreEntities book = new BookStoreEntities();

            GridView1.DataSource = book.Books.ToList();
            GridView1.DataBind();
        }
Ejemplo n.º 6
0
        // need to remove authors from list that are already in the book
        public SelectList GetAuthorUnSelectList(int BookId)
        {
            var context = new BookStoreEntities();

            // performs a left join on book Id and leaves out authors already assigned to the book.
            // this isn't perfect yet.  If we have two different books by the same author, then it will still
            // show up in the add list (just be careful for now).

            var result = (
                from a in context.Author
                join r in context.BookAuthor
                on a.Id equals r.AuthorId into ar
                from ba in ar.DefaultIfEmpty()
                where (ba.BookId != BookId)
                select new SelectListItem
            {
                Value = a.Id.ToString(),
                Text = a.LastName + ", " + a.FirstName
            })
                         .Distinct()
                         .OrderBy(x => x.Text);

            var authorSelectList = new SelectList(
                result, "Value", "Text");

            return(authorSelectList);
        }
Ejemplo n.º 7
0
        // get a generic list of all the authors (not used?)
        public List <AuthorViewModel> GetListOfAuthors()
        {
            var context = new BookStoreEntities();
            var result  = from a in context.Author
                          select new AuthorList()
            {
                Id        = a.Id,
                FirstName = a.FirstName,
                LastName  = a.LastName,
                Biography = a.Biography
            };

            var AuthorsList = new List <AuthorViewModel>();

            foreach (var item in result)
            {
                var author = new AuthorViewModel();
                author.Id        = item.Id;
                author.FirstName = item.FirstName;
                author.LastName  = item.LastName;
                author.Biography = item.Biography;
                AuthorsList.Add(author);
            }

            return(AuthorsList);
        }
Ejemplo n.º 8
0
        // get a generic list of authors for one book
        public List <AuthorViewModel> GetListOfAuthors(int BookId)
        {
            var AuthorsList = new List <AuthorViewModel>();

            var context = new BookStoreEntities();
            var result  = from a in context.Author
                          join r in context.BookAuthor
                          on a.Id equals r.AuthorId
                          where r.BookId == BookId
                          orderby(a.LastName + " " + a.FirstName)
                          select new AuthorList()
            {
                Id        = a.Id,
                FirstName = a.FirstName,
                LastName  = a.LastName,
                Biography = a.Biography
            };

            foreach (var item in result)
            {
                var author = new AuthorViewModel();
                author.Id        = item.Id;
                author.FirstName = item.FirstName;
                author.LastName  = item.LastName;
                author.Biography = item.Biography;
                AuthorsList.Add(author);
            }

            return(AuthorsList);
        }
Ejemplo n.º 9
0
        // PUT api/<controller>/5
        public bool Put(int id, [FromBody] Book p)
        {
            p.Id = id;

            if (p == null)
            {
                throw new ArgumentNullException("p");
            }

            using (var ctx = new BookStoreEntities())
            {
                var book = _context.Books.Single(a => a.Id == p.Id);

                if (book != null)
                {
                    book.Name     = p.Name;
                    book.Category = p.Category;
                    book.Author   = p.Author;
                    book.Price    = p.Price;

                    int rowsAffected = _context.SaveChanges();

                    return(rowsAffected > 0 ? true : false);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 10
0
        // get an IEnumerable list of authors for one book,
        // maybe drive us to change the view model back to IEnumerable

        public IEnumerable <AuthorViewModel> GetAuthors(int BookId)
        {
            var AuthorsList = new List <AuthorViewModel>();

            var context = new BookStoreEntities();
            var result  = from a in context.Author
                          join r in context.BookAuthor
                          on a.Id equals r.AuthorId
                          where r.BookId == BookId
                          select new AuthorList()
            {
                Id        = a.Id,
                FirstName = a.FirstName,
                LastName  = a.LastName,
                Biography = a.Biography
            };

            // copy the IQueryable to the List<AuthorViewModel>
            // would be nice if we didn't have to do this.

            foreach (var item in result)
            {
                var author = new AuthorViewModel();
                author.Id        = item.Id;
                author.FirstName = item.FirstName;
                author.LastName  = item.LastName;
                author.Biography = item.Biography;
                AuthorsList.Add(author);
            }

            return(AuthorsList);
        }
Ejemplo n.º 11
0
        public ActionResult Details()
        {
            BookStoreEntities db = new BookStoreEntities();
            var data             = db.Orders;

            return(View(data));
        }
Ejemplo n.º 12
0
        //
        // GET: /Book/

        public ActionResult Index()
        {
            BookStoreEntities db = new BookStoreEntities();
            var data             = db.Books;

            return(View(data));
        }
Ejemplo n.º 13
0
        public BookController()
        {
            BookStoreEntities _entity = new BookStoreEntities();

            this._bookRepository         = new BookRepository(_entity);
            this._bookCategoryRepository = new BookCategoryRepository(_entity);
        }
Ejemplo n.º 14
0
        public static bool IsUser(HttpCookie ID)
        {
            try
            {
                using (var book = new BookStoreEntities())
                {
                    if (ID == null)
                    {
                        return false;
                    }
                    var userID = ID["UserID"];
                    var person = book.people.Where(x => x.cid.ToString() == userID).ToList();

                    if (person.Count() == 0)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {

                return false;
            }
        }
Ejemplo n.º 15
0
        public ActionResult Admin()
        {
            BookStoreEntities book = new BookStoreEntities();

            List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>();
            using (BookStoreEntities bookEntities = new BookStoreEntities())
            {
                //_books = bookEntities.Books.ToList();
                var books = bookEntities.books.Where(b => b.qtyinstore > 0).ToList();
                foreach (var b in books)
                {

                    _671Books.Models.Book _book = new _671Books.Models.Book();
                    _book.ID = b.bid;
                    _book.Name = b.title;
                    _book.Author = b.author;
                    _book.Genre = b.genre;
                    _book.Year = b.year;
                    _book.Edition = b.edition;
                    _book.Publisher = b.publisher;
                    _book.Price = b.price;
                    _book.QuantityInStore = b.qtyinstore;
                    //_book.QuantitySold = b.qtysold;
                    //_book.BookCover = b.BookCover;

                    _books.Add(_book);

                }
                return View(_books);

            }
        }
Ejemplo n.º 16
0
        // Create
        public bool AddBook(BookModel newBook)
        {
            using (BookStoreEntities ef = new BookStoreEntities())
            {
                //we can find the author by name - because the name is unique
                Author author = ef.Authors.FirstOrDefault(
                    a => a.AuthorName == newBook.BookAuthor.AuthorName
                    );

                Book book = new Book()
                {
                    BookName  = newBook.BookName,
                    BookPrice = newBook.BookPrice,
                    AuthorID  = author.AuthorID
                };

                ef.Books.Add(book);

                try
                {
                    ef.SaveChanges();
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 17
0
        public ActionResult Login(string login, string password)
        {
            using (BookStoreEntities context = new BookStoreEntities())
            {
                // Cach 1: Viet theo dang Method
                var objEmployeeLogin = context.Customers
                                       .Where(p => p.CustomerId == login && p.CustomerPassword == password)
                                       .FirstOrDefault();

                if (objEmployeeLogin == null)
                {
                    TempData["login_oldValue"]    = login;
                    TempData["password_oldValue"] = password;

                    //return "Khong hop le";
                    // validate login
                    if (String.IsNullOrEmpty(login))
                    {
                        TempData["msgLoi_Login"] = "******";
                        return(View("~/Views/Home/Login.cshtml"));
                    }
                    else if (login.Length < 3)
                    {
                        TempData["msgLoi_Login"] = "******";
                        return(View("~/Views/Home/Login.cshtml"));
                    }
                    else
                    {
                        TempData["msgLoi_Login"] = String.Empty;
                    }

                    // validate password
                    if (String.IsNullOrEmpty(password) || password.Length < 3)
                    {
                        TempData["msgLoi_Password"] = "******";
                        return(View("~/Views/Home/Login.cshtml"));
                    }
                    else
                    {
                        TempData["msgLoi_Password"] = String.Empty;
                    }

                    TempData["msgLoi"] = "Login fail. Check your username and password agian please!";
                    return(View("~/Views/Home/Login.cshtml"));
                    //return String.Format("Khong hop le {0} {1}", objEmployeeLogin.EmpName, objEmployeeLogin.EmpRole);
                }
                else
                {
                    //return String.Format("Xin chao anh {0} {1}", objEmployeeLogin.EmpName, objEmployeeLogin.EmpRole);
                    TempData["msgLoi"] = String.Empty;
                    //TempData["username"] = login;
                    Session["LoginUser"] = login;

                    //return View();
                    return(RedirectToAction("/Product"));
                    //return View("~/Views/Home/Product.cshtml");
                }
            }
        }
Ejemplo n.º 18
0
 protected int getStockLevel(string ISBN)
 {
     using (BookStoreEntities m = new BookStoreEntities())
     {
         Book b = m.Books.Where(x => x.ISBN == ISBN).First();
         return(b.StockLevel);
     }
 }
Ejemplo n.º 19
0
        public virtual void Setup()
        {
            var connection = DbConnectionFactory.CreateTransient();

            context = new BookStoreEntities(connection);
            context.Database.CreateIfNotExists();
            unitOfWork = new EFUnitOfWork(context);
        }
Ejemplo n.º 20
0
 public static void InsertBookBySP(BookModel newBook)
 {
     using (BookStoreEntities ef = new BookStoreEntities())
     {
         //here we use the SP that we created in the DB
         ef.InsertBook(newBook.BookName, newBook.BookPrice, newBook.AuthorID);
         ef.SaveChanges();
     }
 }
Ejemplo n.º 21
0
        // DELETE api/<controller>/5
        public bool Delete(int id)
        {
            using (var ctx = new BookStoreEntities())
            {
                Book book = ctx.Books.Find(id);
                ctx.Books.Remove(book);

                int rowsAffected = ctx.SaveChanges();

                return(rowsAffected > 0 ? true : false);
            }
        }
Ejemplo n.º 22
0
        public ActionResult Order(int id)
        {
            BookStoreEntities db = new BookStoreEntities();
            var book             = db.Books.Where(b => b.BookId == id).FirstOrDefault();

            ViewBag.BookId       = book.BookId;
            ViewBag.AuthorName   = book.AuthorName;
            ViewBag.Title        = book.Title;
            ViewBag.Price        = book.Price;
            ViewBag.BookCoverUrl = book.BookCoverUrl;

            return(View());
        }
Ejemplo n.º 23
0
        //the UIL will call this function and send a BOL object
        //the BLL will add the object t the EF
        //and save the changes to the DAL
        public static void InsertBookByDbSet(BookModel newBook)
        {
            using (BookStoreEntities ef = new BookStoreEntities())
            {
                ef.Books.Add(new Book
                {
                    BookName  = newBook.BookName,
                    BookPrice = newBook.BookPrice,
                    AuthorID  = newBook.AuthorID
                });

                ef.SaveChanges();
            }
        }
Ejemplo n.º 24
0
        public void Setup_fake_dbset_returns_expected()
        {
            // Arrange
            var entities = new BookStoreEntities();
            var book     = new Book {
                Title = "title"
            };

            // Act
            entities.SetupFakeDbSet(x => x.Books).Add(book);

            // Assert
            Assert.That(entities.Books.Count(), Is.EqualTo(1));
            Assert.That(entities.Books.First().Title, Is.EqualTo("title"));
        }
        public static List <AuthorModel> GetAllAuthors()
        {
            List <AuthorModel> authors = new List <AuthorModel>();

            using (BookStoreEntities ef = new BookStoreEntities())
            {
                foreach (Author item in ef.Authors)
                {
                    authors.Add(new AuthorModel {
                        AuthorName  = item.AuthorName,
                        AuthorAge   = item.AuthorAge,
                        AuthorImage = item.AuthorImage
                    });
                }
            }
            return(authors);
        }
Ejemplo n.º 26
0
        public AuthorModel GetAuthorById(int id)
        {
            AuthorModel author = null;

            using (BookStoreEntities ef = new BookStoreEntities())
            {
                Author item = ef.Authors.FirstOrDefault(a => a.AuthorID == id);
                if (item != null)
                {
                    author = new AuthorModel()
                    {
                        AuthorAge   = item.AuthorAge,
                        AuthorName  = item.AuthorName,
                        AuthorImage = item.AuthorImage
                    };
                }
            }
            return(author);
        }
Ejemplo n.º 27
0
        public void Setup_fake_dbset_with_add_many_returns_expected()
        {
            // Arrange
            var entities = new BookStoreEntities();
            var book1    = new Book {
                Title = "title 1"
            };
            var book2 = new Book {
                Title = "title 2"
            };

            // Act
            entities.SetupFakeDbSet(x => x.Books).Add(book1, book2);

            // Assert
            Assert.That(entities.Books.Count(), Is.EqualTo(2));
            Assert.That(entities.Books.First().Title, Is.EqualTo("title 1"));
            Assert.That(entities.Books.Last().Title, Is.EqualTo("title 2"));
        }
Ejemplo n.º 28
0
        public ActionResult Admin(FormCollection formCollection)
        {
            List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>();
            using (BookStoreEntities bookEntities = new BookStoreEntities())
            {

                var Author = formCollection["Author"];
                var Genre = (formCollection["Genres"]);
                var Year = (formCollection["Year"]);

                var books = bookEntities.books.ToList();

                if (Author.Length != 0)
                {
                    books = books.Where(b => b.author.ToLower().Contains(Author.ToLower()) && b.qtyinstore > 0).ToList();
                }
                if (Genre.Length != 0)
                {
                    books = books.Where(b => b.genre == Genre && b.qtyinstore > 0).ToList();
                }
                if (Year.Length != 0)
                {
                    books = books.Where(b => b.year.ToString() == Year && b.qtyinstore > 0).ToList();
                }
                foreach (var book in books)
                {
                    _671Books.Models.Book _book = new _671Books.Models.Book();
                    _book.ID = book.bid;
                    _book.Name = book.title;
                    _book.Author = book.author;
                    _book.Genre = book.genre;
                    _book.Year = book.year;
                    _book.Edition = book.edition;
                    _book.Publisher = book.publisher;
                    _book.Price = book.price;
                    _book.QuantityInStore = book.qtyinstore;
                    //_book.QuantitySold = book.qtysold;
                    _books.Add(_book);
                }
                return View(_books);
            }
        }
Ejemplo n.º 29
0
        public ActionResult Order(int BookId, int Num, string Address)
        {
            BookStoreEntities db = new BookStoreEntities();
            var order            = db.Orders.OrderBy(o => o.OrderId).FirstOrDefault();
            var orderid          = 1;

            if (order != null)
            {
                orderid = order.OrderId + 1;
            }
            db.Orders.Add(new Order
            {
                OrderId = orderid,
                BookId  = BookId,
                Num     = Num,
                Address = Address
            });
            db.SaveChanges();
            return(RedirectToAction("Details"));
        }
Ejemplo n.º 30
0
        public ActionResult AddBook(int BookId, string AuthorName, string Title, Nullable <decimal> Price)
        {
            BookStoreEntities db = new BookStoreEntities();

            var book   = db.Books.OrderBy(o => o.BookId).FirstOrDefault();
            var bookId = 1;

            if (book != null)
            {
                bookId = book.BookId + 1;
            }
            db.Books.Add(new Books
            {
                BookId     = BookId,
                AuthorName = AuthorName,
                Title      = Title,
                Price      = Price
            });
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 31
0
        public ActionResult Login(tblUser objUser)
        {
            if (ModelState.IsValid)
            {
                using (BookStoreEntities db = new BookStoreEntities())
                {
                    var obj = db.tblUser.Where(a => a.Username.Equals(objUser.Username) && a.Password.Equals(objUser.Password)).FirstOrDefault();
                    if (obj != null)
                    {
                        Session["User_id"]   = obj.User_id;
                        Session["Username"]  = obj.Username;
                        Session["User_type"] = obj.User_type;

                        if (obj.Username != null && obj.User_type != "Admin")
                        {
                            Session["Username"] = obj.Username;
                            Session["User_id"]  = obj.User_id;
                            return(RedirectToAction("Index", "Home", new { area = "" }));
                        }
                        else if (obj.User_type == "Admin")
                        {
                            Session["Username"] = obj.Username;
                            Session["User_id"]  = obj.User_id;

                            return(RedirectToAction("Admin", "Admin", new { area = "" }));
                        }
                        else if (obj.Username == null)
                        {
                            Session["Username"] = obj.Username;
                            Session["User_ID"]  = obj.User_id;
                            return(RedirectToAction("Login", "Account", new { area = "" }));
                        }
                        else
                        {
                        }
                    }
                }
            }
            return(View(objUser));
        }
Ejemplo n.º 32
0
        public ActionResult Login(FormCollection formCollection)
        {
            var username = formCollection["UserName"];
            var password = formCollection["Password"];

            string existingPassword = "";
            string adminStatus = "no";
            using(BookStoreEntities book = new BookStoreEntities())
            {
                var person = book.people.Where(x => x.username.ToLower() == username.ToLower()).ToList();
                if (person.Count == 0)
                {
                    ViewBag.InvalidUser = "******";

                    return View();
                }
                else
                {
                    existingPassword = person.SingleOrDefault(p => p.username.ToLower() == username.ToLower()).password;
                    if (string.Compare(existingPassword,password) == 0)
                    {
                        HttpCookie myCookie = new HttpCookie("UserSettings");
                        myCookie["UserID"] = person.SingleOrDefault().cid.ToString();
                        myCookie["UserName"] = person.SingleOrDefault().username.ToString();

                        Response.Cookies.Add(myCookie);

                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {

                        ViewBag.InvalidUser = "******";
                        return View();
                    }
                }

            }
            return View();
        }
Ejemplo n.º 33
0
        //public IHttpActionResult getAllBooks()
        //{
        //    IList<BookViewModel> bookList = null;
        //    using (ctx = new BookStoreEntities())
        //    {
        //        bookList = ctx.Books.Select(book => new BookViewModel()
        //        {
        //            BookId = book.BookId,
        //            Bookname = book.Bookname,
        //            Bookprice = book.Bookprice
        //        }).ToList<BookViewModel>();
        //    }
        //    if (bookList.Count == 0)
        //    {
        //        return NotFound();
        //    }
        //    return Ok(bookList);
        //}

        public IHttpActionResult getBooksByName(string bookName)
        {
            IList <BookViewModel> bookList = null;

            using (ctx = new BookStoreEntities())
            {
                bookList = ctx.Books
                           .Where(book => book.Bookname.ToLower() == bookName.ToLower())
                           //.Where(book => book.Bookprice == )
                           .Select(book => new BookViewModel()
                {
                    BookId    = book.BookId,
                    Bookname  = book.Bookname,
                    Bookprice = book.Bookprice
                }).ToList <BookViewModel>();
            }
            if (bookList.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(bookList));
        }
Ejemplo n.º 34
0
        // Delete
        public bool DeleteAuthor(int id)
        {
            using (BookStoreEntities ef = new BookStoreEntities())
            {
                Author deletedAuthor = ef.Authors.FirstOrDefault(a => a.AuthorID == id);
                if (deletedAuthor == null)
                {
                    return(false);
                }
                ef.Authors.Remove(deletedAuthor);

                try
                {
                    ef.SaveChanges();
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 35
0
        public static bool IsAdmin(HttpCookie ID)
        {
            try
            {
                using(var book = new BookStoreEntities())
                {
                    if (ID == null)
                    {
                        return false;
                    }

                    var userID = ID["UserID"];
                     var person = book.people.Where(x => x.cid.ToString() == userID).ToList();
                     var isAdmin = person.SingleOrDefault().admin_status.ToString();
                     if (person.Count() == 0)
                     {
                         return false;
                     }
                     else
                     {
                         if (isAdmin.ToLower() == "yes")
                         {
                             return true;
                         }
                         else
                         {
                             return false;
                         }
                     }
                }
            }
            catch (Exception ex)
            {

                return false;
            }
        }
Ejemplo n.º 36
0
        public ActionResult Register(FormCollection formCollection)
        {
            // Attempt to register the user
            try
            {
                using (BookStoreEntities book = new BookStoreEntities())
                {
                    string error = "";
                    var username = formCollection["UserName"];
                    var password = formCollection["Password"];
                    var phone = formCollection["Phone"];
                    var name = formCollection["Name"];
                    var address = formCollection["Address"];
                    var confirmpassword = formCollection["ConfirmPassword"];
                    if (string.IsNullOrEmpty(username))
                    {
                        error = error + "Please enter Username." + "<br>";
                    }
                    if (string.IsNullOrEmpty(password))
                    {
                        error = error + "Please enter Password." + "<br>";
                    }
                    if (string.Compare(password, confirmpassword) != 0)
                    {
                        error = error + "Password's did not match." + "<br>";
                    }
                    if (string.IsNullOrEmpty(phone))
                    {
                        error = error + "Please enter Phone." + "<br>";
                    }
                    if (string.IsNullOrEmpty(address))
                    {
                        error = error + "Please enter Address." + "<br>";
                    }
                    if (string.IsNullOrEmpty(address))
                    {
                        error = error + "Please enter Address." + "<br>";
                    }
                    if (string.IsNullOrEmpty(error))
                    {
                        var person = book.people.Where(x => x.username.ToLower() == username.ToLower()).ToList();
                        if (person.Count == 0)
                        {
                            var id = book.people.Max(b => b.cid);
                            book.people.Add(new person {cid = id+1, username = username, password = password, phone = Convert.ToInt64(phone), name = name, address = address, admin_status = "no" });
                            book.SaveChanges();
                        }
                        else
                        {
                            ViewBag.ExistingUser = "******";
                            return View();
                        }
                        return RedirectToAction("Login", "User");
                    }
                    else
                    {
                        ViewBag.SummaryDiv = error;
                        return View();
                    }

                }
            }
            catch (Exception ex)
            {

                //return to error page
            }

            // If we got this far, something failed, redisplay form
            return View();
        }
Ejemplo n.º 37
0
        public ActionResult BookDetailsAdmin(FormCollection formCollection)
        {
            var ID = Convert.ToInt32(formCollection["txtID"]);

            var TitleBook = formCollection["TitleBook"];
            var Edition = formCollection["Edition"];
            var Year = formCollection["Year"];
            var Price = formCollection["Price"];
            var Author = formCollection["Author"];
            var Publisher = formCollection["Publisher"];
            var Genre = formCollection["Genre"];
            var QtyInStore = formCollection["QtyInStore"];
            decimal outPrice = 0;
            bool isPriceDecimal = Decimal.TryParse(Price, out outPrice);
            int outYear = 0;
            bool isYearNumerical = Int32.TryParse(Year, out outYear);
            int outQtyInStore = 0;
            bool isQtyInStoreNumerical = Int32.TryParse(QtyInStore, out outQtyInStore);
            int outEdition = 0;
            bool isEditionNumerical = Int32.TryParse(Edition, out outEdition);
            bool flag = true;
            bool numflag = true;
            string error = "";
            if (string.IsNullOrEmpty(TitleBook))
            {
                flag = false;
            }
            if (string.IsNullOrEmpty(Edition))
            {
                flag = false;
            }
            if (string.IsNullOrEmpty(Year))
            {
                flag = false;
            }
            if (string.IsNullOrEmpty(Author))
            {
                flag = false;
            }
            if (string.IsNullOrEmpty(Publisher))
            {
                flag = false;
            }
            if (string.IsNullOrEmpty(Genre))
            {
                flag = false;
            }
            if (string.IsNullOrEmpty(Price))
            {
                flag = false;
            }
            if (string.IsNullOrEmpty(QtyInStore))
            {
                flag = false;
            }
            if (!isPriceDecimal)
            {
                numflag = false;
            }
            if (!isYearNumerical)
            {
                numflag = false;
            }
            if (!isEditionNumerical)
            {
                numflag = false;
            }
            if (!isQtyInStoreNumerical)
            {
                numflag = false;
            }
            if (flag)
            {
                if (numflag)
                {
                    using (BookStoreEntities book = new BookStoreEntities())
                    {
                        //var bookToRemove = book.books.Where(b => b.bid == ID);
                        //book.books.RemoveRange(bookToRemove);
                        //book.SaveChanges();

                        //book.books.Add(new book { bid = ID, title = TitleBook, edition = Edition, author = Author, genre = Genre, price = Price, publisher = Publisher, year = Year, qtyinstore = QtyInStore, qtysold = 0 });
                        //book.SaveChanges();
                        var bookToFind = book.books.Find(ID);
                        bookToFind.author = Author;
                        bookToFind.edition = outEdition;
                        bookToFind.year = outYear;
                        bookToFind.publisher = Publisher;
                        bookToFind.genre = Genre;
                        bookToFind.price = outPrice;
                        bookToFind.qtyinstore = outQtyInStore;
                        bookToFind.title = TitleBook;
                        book.SaveChanges();
                    }
                }
                else
                {
                    ViewBag.SummaryDiv = "Please enter valid values";
                    _671Books.Models.Book _book = new _671Books.Models.Book();
                    BookStoreEntities book = new BookStoreEntities();
                    var books = book.books.ToList();
                    books = books.Where(b => b.bid == ID).ToList();

                    foreach (var b in books)
                    {
                        _book.ID = b.bid;
                        _book.Name = b.title;
                        _book.Author = b.author;
                        _book.Genre = b.genre;
                        _book.Year = b.year;
                        _book.Edition = b.edition;
                        _book.Publisher = b.publisher;
                        _book.Price = b.price;
                        _book.QuantityInStore = b.qtyinstore;
                        //_book.QuantitySold = b.qtysold;
                        // _book.BookCover = b.BookCover;
                    }
                    return View(_book);
                }
            }
            else
            {
                ViewBag.SummaryDiv = "Please enter all values";
                _671Books.Models.Book _book = new _671Books.Models.Book();
                BookStoreEntities book = new BookStoreEntities();
                var books = book.books.ToList();
                books = books.Where(b => b.bid == ID).ToList();

                foreach (var b in books)
                {
                    _book.ID = b.bid;
                    _book.Name = b.title;
                    _book.Author = b.author;
                    _book.Genre = b.genre;
                    _book.Year = b.year;
                    _book.Edition = b.edition;
                    _book.Publisher = b.publisher;
                    _book.Price = b.price;
                    _book.QuantityInStore = b.qtyinstore;
                    //_book.QuantitySold = b.qtysold;
                    // _book.BookCover = b.BookCover;
                }
                return View(_book);
            }

            return RedirectToAction("Admin", "Home");
        }
Ejemplo n.º 38
0
        public ActionResult RemoveCart(string ID)
        {
            string userSettings = "0";
            if (Request.Cookies["UserSettings"] != null)
            {

                if (Request.Cookies["UserSettings"]["UserID"] != null)
                { userSettings = Request.Cookies["UserSettings"]["UserID"]; }
            }
            using (BookStoreEntities book = new BookStoreEntities())
            {
                var bookToRemove = book.Carts.Where(b => b.bid.ToString() == ID && b.cid.ToString() == userSettings);
                book.Carts.RemoveRange(bookToRemove);
                book.SaveChanges();
            }
            return RedirectToAction("Cart", "Home");
        }
Ejemplo n.º 39
0
 public ActionResult BookDetails(string ID, string Source)
 {
     _671Books.Models.Book _book = new _671Books.Models.Book();
     BookStoreEntities book = new BookStoreEntities();
     var books = book.books.ToList();
     books = books.Where(b => b.bid.ToString() == ID).ToList();
     if (Source != "Index")
     {
         ViewBag.DisplayButton = "display:none";
         ViewBag.DisplayRemoveButton = "display:block";
     }
     else {
         ViewBag.DisplayButton = "display:block";
         ViewBag.DisplayRemoveButton = "display:none";
     }
     foreach (var b in books)
     {
         _book.ID = b.bid;
         _book.Name = b.title;
         _book.Author = b.author;
         _book.Genre = b.genre;
         _book.Year = b.year;
         _book.Edition = b.edition;
         _book.Publisher = b.publisher;
         _book.Price = b.price;
         _book.QuantityInStore = b.qtyinstore;
         //_book.QuantitySold = b.qtysold;
        // _book.BookCover = b.BookCover;
     }
     return View(_book);
 }
Ejemplo n.º 40
0
        public ActionResult NewBook(FormCollection formCollection)
        {
            //var ID = Convert.ToInt32(formCollection["ID"]);

            var TitleBook = formCollection["TitleBook"];
            var Edition = formCollection["Edition"];
            var Year = formCollection["Year"];
            var Price = formCollection["Price"];
            var Author = formCollection["Author"];
            var Publisher = formCollection["Publisher"];
            var Genre = formCollection["Genre"];
            var QtyInStore = formCollection["QtyInStore"];
            decimal outPrice = 0;
            bool isPriceDecimal = Decimal.TryParse(Price, out outPrice);
            int outYear = 0;
            bool isYearNumerical = Int32.TryParse(Year, out outYear);
            int outQtyInStore = 0;
            bool isQtyInStoreNumerical = Int32.TryParse(QtyInStore, out outQtyInStore);
            int outEdition = 0;
            bool isEditionNumerical = Int32.TryParse(Edition, out outEdition);
            bool flag = true;
            bool numflag = true;
            string error = "";
            if (string.IsNullOrEmpty(TitleBook))
            {
                flag = false;
            }
            if (string.IsNullOrEmpty(Edition))
            {
                flag = false;
            }
            if (string.IsNullOrEmpty(Year))
            {
                flag = false;
            }
            if(string.IsNullOrEmpty(Author))
            {
                flag = false;
            }
             if(string.IsNullOrEmpty(Publisher))
            {
                flag = false;
            }
             if(string.IsNullOrEmpty(Genre))
            {
                flag = false;
            }
            if(string.IsNullOrEmpty(Price))
            {
                flag = false;
            }
             if(string.IsNullOrEmpty(QtyInStore))
            {
                flag = false;
            }
             if (!isPriceDecimal)
             {
                 numflag = false;
             }
             if (!isYearNumerical)
             {
                 numflag = false;
             }
             if (!isEditionNumerical)
             {
                 numflag = false;
             }
             if (!isQtyInStoreNumerical)
             {
                 numflag = false;
             }
             if (flag)
             {
                 if (numflag)
                 {
                     using (BookStoreEntities book = new BookStoreEntities())
                     {
                         var ID = book.books.Max(b => b.bid);
                         book.books.Add(new book { bid = ID + 1, title = TitleBook, edition = outEdition, author = Author, genre = Genre, price = outPrice, publisher = Publisher, year = outYear, qtyinstore = outQtyInStore});
                         book.SaveChanges();
                     }
                 }
                 else
                 {
                     ViewBag.SummaryDiv = "Please enter valid values";
                     return View();
                 }
             }
             else
             {
                 ViewBag.SummaryDiv = "Please enter all values";
                 return View();
             }
             return RedirectToAction("Admin", "Home");
        }
Ejemplo n.º 41
0
        public ActionResult OrderHistory()
        {
            //List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>();
            List<_671Books.Models.Orders> _orders = new List<_671Books.Models.Orders>();
            string userSettings = "";
            if (Request.Cookies["UserSettings"] != null)
            {
                if (Request.Cookies["UserSettings"]["UserID"] != null)
                { userSettings = Request.Cookies["UserSettings"]["UserID"]; }
            }
            using (BookStoreEntities _book = new BookStoreEntities())
            {
                //var userBooks = _book.Orders.Where(b => b.cid.ToString() == userSettings).ToList();
                var userBooks = _book.GetOrderHistory().Where(b => b.cid.ToString() == userSettings).ToList();
                foreach (var b in userBooks)
                {
                    //_671Books.Models.Book book = new _671Books.Models.Book();
                    _671Books.Models.Orders order = new _671Books.Models.Orders();

                    //book.Author = b.author;
                    //book.Edition = b.edition;
                    //book.Genre = b.genre;
                    //book.ID = b.bid;

                    //book.Name = b.title;
                    //book.Price = b.price;
                    //book.Publisher = b.publisher;

                    //book.Year = b.year;
                    //_books.Add(book);
                    //order.ID = b.cid;
                    order.OrderID = b.orderid;
                    order.OrderDate = b.orderdate.ToShortDateString();
                    order.TotalPrice = b.totalprice;
                    order.ShippingAddress = b.shippingaddress;
                    order.Quantity = b.qtysold;
                    order.name = b.title;
                    order.publisher = b.publisher;
                    order.author = b.author;
                    order.genre = b.genre;
                    order.year = b.year;
                    order.edition = b.edition;
                    order.price = b.price;
                    order.Status = b.Status;
                    _orders.Add(order);
                }
            }
            return View(_orders);
        }
Ejemplo n.º 42
0
        public ActionResult Checkout(FormCollection formCollection)
        {
            List<string> ID = new List<string>();
            List<string> a = new List<string>();
            int count = 0;
            string value = "";
            decimal total = 0;
            //string[] a = new string[100];
            string userSettings = "0";
            if (Request.Cookies["UserSettings"] != null)
            {
                if (Request.Cookies["UserSettings"]["UserID"] != null)
                { userSettings = Request.Cookies["UserSettings"]["UserID"]; }
            }
            using(BookStoreEntities book = new BookStoreEntities())
            {
                foreach (var key in formCollection.AllKeys)
                {

                    if (key.Contains("txt"))
                    {
                         value = formCollection["txt"];
                        //a = value.Split(',');

                    }
                    else
                    {
                        var v = key;
                        ID.Add(v);
                    }

                    //var value = formCollection[key];
                    //var ID = key.Substring(2, key.Length - 3);
                    //if (key.Contains("txt"))
                    //{
                    //    var value = formCollection[key];
                    //    var ID = key.Substring(3, key.Length - 3);
                    //
                }
                 Random r = new Random();
                int n = r.Next(1000001, 9999999);

                string[] b = value.Split(',');
                for (int j = 0; j < b.Count(); j++)
                {
                    a.Add(b[j]);
                }
                var bookToRemove = book.Carts.Where(_book => _book.cid.ToString() == userSettings && _book.orderStatus == "Placed");
                book.Carts.RemoveRange(bookToRemove);
                book.SaveChanges();

                    for (int i = 0; i < a.Count(); i++)
                    {
                        var id = ID[i];
                        var originalRecord = book.books.FirstOrDefault(x => x.bid.ToString() ==  id);
                        if (originalRecord != null)
                        {
                            var num = Convert.ToDecimal(a[i]);
                            total = total + num;
                            var den = Convert.ToDecimal(originalRecord.price);
                            var qty = num / den;
                            //book.Carts.Add(new Cart { cid = Convert.ToInt32(userSettings), bid = originalRecord.bid, price = Convert.ToDecimal(a[i]), title = originalRecord.title, qty =  (int)qty, edition = originalRecord.edition, year = originalRecord.year, author = originalRecord.author, publisher = originalRecord.publisher, genre = originalRecord.genre,inWishList = false, orderStatus = "Ordered", qtyinstore = originalRecord.qtyinstore});
                            //book.SaveChanges();
                        }
                        // book.Carts.Add(new Cart { cid = Convert.ToInt32(userSettings), bid = Convert.ToInt32(ID[i]), });
                    }
                    book.Orders.Add(new Order { cid = Convert.ToInt32(userSettings), orderdate = DateTime.Now, shippingaddress = "123 Shipping Address", Status = "Ordered", totalprice = total, orderid = n });
                    book.SaveChanges();
            }

            return View();
        }
Ejemplo n.º 43
0
        public ActionResult MyAccount()
        {
            List<_671Books.Models.Person> _people = new List<_671Books.Models.Person>();
             string userSettings = "0";
            if (Request.Cookies["UserSettings"] != null)
            {
                if (Request.Cookies["UserSettings"]["UserID"] != null)
                { userSettings = Request.Cookies["UserSettings"]["UserID"]; }
            }
            using (BookStoreEntities book = new BookStoreEntities())
            {
                var person = book.people.Where(p => p.cid.ToString() == userSettings).ToList();
                foreach (var p in person)
                {
                    _671Books.Models.Person _person = new _671Books.Models.Person();
                    _person.ID = p.cid;
                    _person.Name = p.name;
                    _person.Phone = p.phone;
                    _person.Address = p.address;
                    _person.UserName = p.username;
                    _person.Password = p.password;

                    _people.Add(_person);
                }
                return View(_people);

            }
        }
Ejemplo n.º 44
0
        public ActionResult WishList()
        {
            List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>();

            string userSettings = "";
            if (Request.Cookies["UserSettings"] != null)
            {
                if (Request.Cookies["UserSettings"]["UserID"] != null)
                { userSettings = Request.Cookies["UserSettings"]["UserID"]; }
            }
            using (BookStoreEntities _book = new BookStoreEntities())
            {
                var userBooks = _book.Carts.Where(b => b.cid.ToString() == userSettings && b.inWishList == true).ToList();
                foreach (var b in userBooks)
                {
                    _671Books.Models.Book book = new _671Books.Models.Book();
                    book.Author = b.author;
                    //book.BookCover
                    book.Edition = b.edition;
                    book.Genre = b.genre;
                    book.ID = b.bid;
                    //book.ISBN = b.i
                    book.Name = b.title;
                    book.Price = b.price;
                    book.Publisher = b.publisher;

                    book.Year = b.year;
                    _books.Add(book);
                }
            }
            return View(_books);
        }
Ejemplo n.º 45
0
        public ActionResult Cart(FormCollection formCollection)
        {
            int n = 0;
            var Name = formCollection["Name"];
            var ShippingAddress = formCollection["ShippingAddress"];
            var BillingAddress = formCollection["BillingAddress"];
            var Card = formCollection["Card"];
            var CVV = formCollection["CVV"];
            long cardInt;
            bool isCardNumerical =  Int64.TryParse(Card, out cardInt);
            //string error = "";
            int cvvInt;
            bool isCVVNumerical = Int32.TryParse(CVV, out cvvInt);
            var error = new StringBuilder();

            if (string.IsNullOrEmpty(Name))
            {
                error.AppendLine("Please enter a Name");
                error.AppendLine();
                //error = error + "Please enter a Name" + "\n" ;
            }
            if (string.IsNullOrEmpty(ShippingAddress))
            {
                //error = error  + "Please enter Shipping Address" + "\n";
                error.AppendLine("Please enter Shipping Address");
                error.AppendLine();
            }
            if (string.IsNullOrEmpty(BillingAddress))
            {
                //error = error + "Please enter Billing Address" + "\n";
                error.Append("Please enter Billing Address");
                error.AppendLine();
            }
            if (string.IsNullOrEmpty(Card))
            {
                //error = error + "Please enter Credit Card Number" + "\n";
                error.Append("Please enter Credit Card Number");
                error.AppendLine();
            }
            if (string.IsNullOrEmpty(CVV))
            {
                //error = error + "Please enter CVV Number" + "\n";
                error.Append("Please enter CVV Number");
                error.AppendLine();
            }
            if (!isCardNumerical)
            {
                //error = error + "Please enter valid Credit Card Number" + "\n";
                error.Append("Please enter valid Credit Card Number");
                error.AppendLine();
            }
            if (!isCVVNumerical)
            {
                //error = error + "Please enter valid CVV Number" + "\n";
                error.Append("Please enter valid CVV Number");
                error.AppendLine();
            }
            error = error.Replace("\n", Environment.NewLine);
            ViewBag.SummaryDiv = error.ToString();
            List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>();
            if (error.Length == 0)
            {
                List<string> ID = new List<string>();
                List<string> a = new List<string>();
                int count = 0;
                string value = "";
                decimal total = 0;
                //string[] a = new string[100];
                string userSettings = "0";
                if (Request.Cookies["UserSettings"] != null)
                {
                    if (Request.Cookies["UserSettings"]["UserID"] != null)
                    { userSettings = Request.Cookies["UserSettings"]["UserID"]; }
                }
                using (BookStoreEntities book = new BookStoreEntities())
                {
                    foreach (var key in formCollection.AllKeys)
                    {
                        if (key != "Name" && key != "ShippingAddress" && key != "BillingAddress" && key != "Card" && key != "MM" && key != "YY" && key != "CVV" && key != "placeOrder")
                        {
                            if (key.Contains("txt"))
                            {
                                value = formCollection["txt"];
                                //a = value.Split(',');

                            }
                            else
                            {
                                var v = key;
                                ID.Add(v);
                            }
                        }

                        //var value = formCollection[key];
                        //var ID = key.Substring(2, key.Length - 3);
                        //if (key.Contains("txt"))
                        //{
                        //    var value = formCollection[key];
                        //    var ID = key.Substring(3, key.Length - 3);
                        //
                    }
                    Random r = new Random();
                    n = r.Next(1000001, 9999999);

                    string[] b = value.Split(',');
                    for (int j = 0; j < b.Count(); j++)
                    {
                        a.Add(b[j]);
                    }
                    var bookToRemove = book.Carts.Where(_book => _book.cid.ToString() == userSettings && _book.orderStatus == "Placed");
                    book.Carts.RemoveRange(bookToRemove);
                    book.SaveChanges();

                    decimal qty = 0;
                    for (int i = 0; i < a.Count(); i++)
                    {
                        var id = ID[i];
                        var originalRecord = book.books.FirstOrDefault(x => x.bid.ToString() == id);
                        if (originalRecord != null)
                        {
                            var num = Convert.ToDecimal(a[i]);
                            total = total + num;
                            var den = Convert.ToDecimal(originalRecord.price);
                            qty = num / den;
                            //book.Carts.Add(new Cart { cid = Convert.ToInt32(userSettings), bid = originalRecord.bid, price = Convert.ToDecimal(a[i]), title = originalRecord.title, qty =  (int)qty, edition = originalRecord.edition, year = originalRecord.year, author = originalRecord.author, publisher = originalRecord.publisher, genre = originalRecord.genre,inWishList = false, orderStatus = "Ordered", qtyinstore = originalRecord.qtyinstore});
                            //book.SaveChanges();
                            book.Orders.Add(new Order { cid = Convert.ToInt32(userSettings), bid=originalRecord.bid, orderdate = DateTime.Now, shippingaddress = ShippingAddress, Status = "Ordered", totalprice = num, orderid = n, qtysold = Convert.ToInt32(qty) });
                            book.SaveChanges();
                        }
                        // book.Carts.Add(new Cart { cid = Convert.ToInt32(userSettings), bid = Convert.ToInt32(ID[i]), });
                    }
                    //uncomment following if the above logic fails
                    //book.Orders.Add(new Order { cid = Convert.ToInt32(userSettings), orderdate = DateTime.Now, shippingaddress = ShippingAddress, Status = "Ordered", totalprice = total, orderid = n, qtysold = Convert.ToInt32(qty) });
                    //book.SaveChanges();
                }
                return RedirectToAction("Confirmation", "Home", new {orderNumber = n});
            }
            else {
                string userSettings = "0";
                if (Request.Cookies["UserSettings"] != null)
                {
                    if (Request.Cookies["UserSettings"]["UserID"] != null)
                    { userSettings = Request.Cookies["UserSettings"]["UserID"]; }
                }
                using (BookStoreEntities _book = new BookStoreEntities())
                {
                    var userBooks = _book.Carts.Where(b => b.cid.ToString() == userSettings && b.inWishList == false && b.orderStatus == "Placed").ToList();
                    foreach (var b in userBooks)
                    {
                        _671Books.Models.Book book = new _671Books.Models.Book();
                        book.Author = b.author;
                        //book.BookCover
                        book.Edition = b.edition;
                        book.Genre = b.genre;
                        book.ID = b.bid;
                        //book.ISBN = b.i
                        book.Name = b.title;
                        book.Price = b.price;
                        book.Publisher = b.publisher;
                        book.QuantityInStore = b.qtyinstore;
                        book.Year = b.year;
                        _books.Add(book);
                    }

                }
                return View(_books);
            }
        }
Ejemplo n.º 46
0
        public ActionResult Register(FormCollection formCollection)
        {
            // Attempt to register the user
               using(BookStoreEntities book = new BookStoreEntities())
               {
                    var username = formCollection["UserName"];
                    var password = formCollection["Password"];
                    var phone = formCollection["Phone"];
                    var name = formCollection["Name"];
                    var address = formCollection["Address"];
                   var person = book.people.Where(x => x.username == username);
                   if(person == null)
                   {
                       book.people.Add(new person { username = username, password = password, phone = Convert.ToInt64(phone), name = name, address= address });
                       book.SaveChanges();
                   }

                    return RedirectToAction("Index", "Home");

               }

                // If we got this far, something failed, redisplay form
            return View();
        }
Ejemplo n.º 47
0
        public ActionResult BookDetails(FormCollection formCollection, string wishlist, string addtocart, string continuetoshopping, string removewishlist)
        {
            var ID = formCollection["txtID"];
            var QtyInStore = formCollection["txtQtyInStore"];
            string userSettings="0";
            if (Request.Cookies["UserSettings"] != null)
            {

                if (Request.Cookies["UserSettings"]["UserID"] != null)
                { userSettings = Request.Cookies["UserSettings"]["UserID"]; }
            }

            if (wishlist != null)
            {
                using (BookStoreEntities book = new BookStoreEntities())
                {
                    var alreadyexisting = book.Carts.Where(b => b.bid.ToString() == ID && b.cid.ToString() == userSettings).ToList();
                    if(alreadyexisting.Count() == 0)
                    {
                        var _bookCart = book.books.Where(b => b.bid.ToString() == ID).ToList();
                        foreach (var b in _bookCart)
                        {
                            //Add customerid as well
                            book.Carts.Add(new Cart { cid = Convert.ToInt32(userSettings), bid = b.bid, title = b.title, author = b.author, edition = b.edition, genre = b.genre, price = b.price, publisher = b.publisher, inWishList = true, orderStatus = "WishList", year = b.year, qtyinstore = b.qtyinstore });
                            book.SaveChanges();
                        }
                    }

                }
                return RedirectToAction("Index", "Home");
            }
            if (addtocart != null)
            {

                using (BookStoreEntities book = new BookStoreEntities())
                {
                    var alreadyexisting = book.Carts.SingleOrDefault(b => b.bid.ToString() == ID && b.cid.ToString() == userSettings);
                    if (alreadyexisting == null)
                    {
                        var _bookCart = book.books.Where(b => b.bid.ToString() == ID).ToList();
                        foreach (var b in _bookCart)
                        {
                            //Add customerid as well
                            book.Carts.Add(new Cart { cid = Convert.ToInt32(userSettings), bid = b.bid, title = b.title, author = b.author, edition = b.edition, genre = b.genre, price = b.price, publisher = b.publisher, inWishList = false, orderStatus = "Placed", year = b.year, qtyinstore = b.qtyinstore });
                            book.SaveChanges();
                        }
                    }
                    else
                    {
                        if (alreadyexisting.inWishList == true)
                        {
                            var cid = Convert.ToInt32(userSettings);
                            var bid = Convert.ToInt32(ID);
                            var _bookCart = book.books.Where(b => b.bid.ToString() == ID).ToList();

                            var bookToRemove = book.Carts.Where(b => b.bid.ToString() == ID && b.cid.ToString() == userSettings);
                            book.Carts.RemoveRange(bookToRemove);
                            book.SaveChanges();

                            foreach (var b in _bookCart)
                            {
                                book.Carts.Add(new Cart { cid = Convert.ToInt32(userSettings), bid = b.bid, title = b.title, author = b.author, edition = b.edition, genre = b.genre, price = b.price, publisher = b.publisher, inWishList = false, orderStatus = "Placed", year = b.year, qtyinstore = b.qtyinstore });
                                book.SaveChanges();
                            }
                        }
                    }

                }
                return RedirectToAction("Index", "Home");
            }
            if(removewishlist != null)
            {
                using (BookStoreEntities book = new BookStoreEntities())
                {
                    var bookToRemove = book.Carts.Where(b => b.bid.ToString() == ID && b.cid.ToString() == userSettings);
                    book.Carts.RemoveRange(bookToRemove);
                    book.SaveChanges();
                }
                return RedirectToAction("WishList", "Home");
            }
            if (continuetoshopping != null)
            {
            }
               return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 48
0
        public ActionResult BookDetailsAdmin(string ID)
        {
            _671Books.Models.Book _book = new _671Books.Models.Book();
            BookStoreEntities book = new BookStoreEntities();
            var books = book.books.ToList();
            books = books.Where(b => b.bid.ToString() == ID).ToList();

            foreach (var b in books)
            {
                _book.ID = b.bid;
                _book.Name = b.title;
                _book.Author = b.author;
                _book.Genre = b.genre;
                _book.Year = b.year;
                _book.Edition = b.edition;
                _book.Publisher = b.publisher;
                _book.Price = b.price;
                _book.QuantityInStore = b.qtyinstore;
                //_book.QuantitySold = b.qtysold;
                // _book.BookCover = b.BookCover;
            }
            return View(_book);
        }
Ejemplo n.º 49
0
        public ActionResult TotalSales(FormCollection formCollection)
        {
            var fromdate = Convert.ToDateTime(formCollection["fromdate"]);
            var todate = Convert.ToDateTime(formCollection["todate"]);

            ViewBag.fromdate = fromdate;
            ViewBag.todate = todate;
            List<_671Books.Models.Orders> orders = new List<_671Books.Models.Orders>();
            using (BookStoreEntities book = new BookStoreEntities())
            {
                //var order = book.Orders.Where(o => o.orderdate >= fromdate && o.orderdate <= todate).ToList();
                var order = book.GetOrderHistory().Where(o => o.orderdate >= fromdate && o.orderdate <= todate).ToList();
                ViewBag.Orders = "orders";
                foreach (var o in order)
                {
                    _671Books.Models.Orders _order = new _671Books.Models.Orders();
                    _order.OrderID = o.orderid;
                    _order.OrderDate = o.orderdate.ToShortDateString();
                    _order.TotalPrice = o.totalprice;
                    _order.name = o.title;
                    _order.publisher = o.publisher;
                    _order.genre = o.genre;
                    _order.edition = o.edition;
                    _order.author = o.author;
                    _order.year = o.year;

                    orders.Add(_order);
                }
            }
            return View(orders);
        }
Ejemplo n.º 50
0
        public ActionResult Cart()
        {
            List<_671Books.Models.Book> _books = new List<_671Books.Models.Book>();

            string userSettings = "0";
            if (Request.Cookies["UserSettings"] != null)
            {
                if (Request.Cookies["UserSettings"]["UserID"] != null)
                { userSettings = Request.Cookies["UserSettings"]["UserID"]; }
            }
            using (BookStoreEntities _book = new BookStoreEntities())
            {
                var userBooks = _book.Carts.Where(b => b.cid.ToString() == userSettings && b.inWishList == false && b.orderStatus == "Placed").ToList();
                foreach (var b in userBooks)
                {
                    _671Books.Models.Book book = new _671Books.Models.Book();
                    book.Author = b.author;
                    //book.BookCover
                    book.Edition = b.edition;
                    book.Genre = b.genre;
                    book.ID = b.bid;
                    //book.ISBN = b.i
                    book.Name = b.title;
                    book.Price = b.price;
                    book.Publisher = b.publisher;
                    book.QuantityInStore = b.qtyinstore;
                    book.Year = b.year;
                    _books.Add(book);
                }
                //ViewBag.ModelCount = _books.Count();
                //for (var i = 0; i < userBooks.Count; i++ )
                //{
                //    book.Author = userBooks[i].author;
                //    //book.BookCover
                //    book.Edition = userBooks[i].edition;
                //    book.Genre = userBooks[i].genre;
                //    book.ID = userBooks[i].bid;
                //    //book.ISBN = b.i
                //    book.Name = userBooks[i].title;
                //    book.Price = userBooks[i].price;
                //    book.Publisher = userBooks[i].publisher;
                //    book.QuantityInStore = userBooks[i].qtyinstore;
                //    book.Year = userBooks[i].year;
                //    _books.Add(book);
                //}
            }
            return View(_books);
        }