Example #1
0
        //this logic is used to fetch the values present in the rating column in the table
        public RatingViewModel Ratings()
        {
            RatingViewModel model = new RatingViewModel();

            try
            {
                using (var db = new Orchard9Entities())
                {
                    model.Ratings = (from book in db.tblBooks
                                     where book.isactive == true
                                     orderby book.Rating ascending
                                     select book.Rating).Distinct().ToList();
                }

                if (model.Ratings.Count > 0)
                {
                    model.StatusMessage = "Success";
                }
                else
                {
                    model.StatusMessage = "No Categories found";
                }
            }

            catch (Exception ex)
            {
                model.StatusMessage = ex.Message;
            }
            return(model);
        }
        /// <summary>
        /// User To Partner
        /// </summary>
        /// <param name="userToPartner"></param>
        /// <returns></returns>

        public ForgotPasswordViewModel UserToPartner(ForgotPasswordViewModel userToPartner)
        {
            ForgotPasswordViewModel logModel = new ForgotPasswordViewModel();

            try
            {
                if (userToPartner != null)
                {
                    using (var db = new Orchard9Entities())
                    {
                        var v  = db.tblUsers.Where(a => a.EmailId == userToPartner.EmailId && a.UserType != "External").FirstOrDefault();
                        var v1 = db.tblUsers.Where(a => a.EmailId == userToPartner.EmailId && a.IsActive == false).FirstOrDefault();
                        var v2 = db.tblUsers.Where(a => a.EmailId == userToPartner.EmailId && a.Role == 5).FirstOrDefault();

                        if (v1 != null)
                        {
                            logModel.StatusMessage = "You are Blocked by Admin";
                            return(logModel);
                        }

                        if (v != null)
                        {
                            if (string.Compare(userToPartner.Password, v.Password) == 0)
                            {
                                if (v2 != null)
                                {
                                    logModel.StatusMessage = "You are already in the Waiting List";
                                    return(logModel);
                                }

                                db.tblUsers.Where(u => u.EmailId == userToPartner.EmailId).ToList().ForEach(s => s.Role = 5);
                                db.SaveChanges();
                                logModel.StatusMessage = "Successfully Added to Partner waiting list";
                                return(logModel);
                            }
                            else
                            {
                                logModel.StatusMessage = "Invalid Password";
                                return(logModel);
                            }
                        }
                        else
                        {
                            logModel.StatusMessage = "External Users Cannot become partner without registration ";
                            return(logModel);
                        }
                    }
                }
                else
                {
                    logModel.StatusMessage = "Input model is empty";
                    return(logModel);
                }
            }
            catch (Exception ex)
            {
                logModel.StatusMessage = ex.Message;
                return(logModel);
            }
        }
Example #3
0
        public string Buy(int UserId)  //This method is change the payment status of the items
        {                              //in the cart when the user clicks on the buy button.
            string str;

            try
            {
                using (var db = new Orchard9Entities())
                {
                    if ((from e in db.tblUsers where e.UserId == UserId && e.IsActive == false select e.UserId).ToList().Count > 0)
                    {
                        return("You are Blocked by Admin");
                    }
                    else
                    {
                        db.tblCarts.Where(u => u.UserId == UserId).ToList().ForEach(s => s.PayStatus = false);
                        db.SaveChanges();
                        str = "Payment Successfull";
                    }
                }
            }
            catch (Exception e)
            {
                str = e.Message;
            }
            return(str);
        }
Example #4
0
        //gets the details of the particular book in the wishlist
        public WishListStatus getBookDetails(int wishListID)
        {
            WishListStatus a = new WishListStatus();

            try
            {
                using (var dbcontext = new Orchard9Entities())

                {
                    var query = (from e in dbcontext.tblWishlists
                                 join d in dbcontext.tblBooks on e.ISBN equals d.ISBN
                                 join x in dbcontext.tblUsers on e.UserId equals x.UserId
                                 where e.id == wishListID
                                 select new WishListModel()
                    {
                        id = e.id, ISBN = e.ISBN, UserId = e.UserId, price = d.Price, Publisher = d.Publisher, Author = d.Author, rating = d.Rating, BookName = d.BookName, BookImageUrl = d.BookImageUrl
                    }).ToList();
                    a.statusList = query;
                    if (query.Count > 0)
                    {
                        a.statusMessage = "book details";
                    }
                    else
                    {
                        a.statusMessage = "book not available";
                    }
                }
            }
            catch (Exception e)
            {
                a.statusMessage = e.Message;
            }
            return(a);
        }
Example #5
0
        //Adds the book from wishlist to cart
        public string addToCart(WishListModel wish)
        {
            string s = "";

            try
            {
                using (var dbcontext = new Orchard9Entities())
                {
                    if ((from e in dbcontext.tblCarts where e.ISBN == wish.ISBN && e.UserId == wish.UserId select e.CartId).ToList().Count > 0)
                    {
                        return("Already present");
                    }
                    else
                    {
                        dbcontext.tblCarts.Add(new tblCart()
                        {
                            CartId    = wish.id,
                            ISBN      = wish.ISBN,
                            UserId    = wish.UserId,
                            PayStatus = true,
                            Quantity  = 1
                        });
                        dbcontext.SaveChanges();
                        return("Added to cart");
                    }
                }
            }
            catch (Exception e)
            {
                s = e.Message;
            }
            return(s);
        }
        //-------------------------------------------------------Partner Forgot Password--------------------------------------------------------

        /// <summary>
        /// Partner Forgot Password
        /// </summary>
        /// <param name="Email"></param>
        /// <returns></returns>
        public ForgotPasswordViewModel PartnerForgotPassword(string Email)
        {
            ForgotPasswordViewModel passModel = new ForgotPasswordViewModel();

            try
            {
                if (!string.IsNullOrEmpty(Email))
                {
                    using (var db = new Orchard9Entities())
                    {
                        var v  = db.tblUsers.Where(a => a.EmailId == Email && a.UserType == "Normal" && a.Role == 3).FirstOrDefault();
                        var v1 = db.tblUsers.Where(a => a.EmailId == Email && a.IsActive == true).FirstOrDefault();


                        if (v != null)
                        {
                            if (v1 == null)
                            {
                                passModel.StatusMessage = "Account is Blocked";
                                return(passModel);
                            }
                            if (!v.IsVerified)
                            {
                                passModel.StatusMessage = "Email Not Verified";
                                return(passModel);
                            }
                            else
                            {
                                passModel = (from res in db.tblUsers
                                             where res.EmailId == Email
                                             select new ForgotPasswordViewModel
                                {
                                    UserId = res.UserId,
                                    EmailId = res.EmailId,
                                    Password = res.Password
                                }).FirstOrDefault();
                                passModel.StatusMessage = "Records found! Check Email for Password";
                                return(passModel);
                            }
                        }
                        else
                        {
                            passModel.StatusMessage = "Email Id is not Present";
                            return(passModel);
                        }
                    }
                }
                else
                {
                    passModel.StatusMessage = "Email Id is empty";
                    return(passModel);
                }
            }
            catch (Exception ex)
            {
                passModel.StatusMessage = ex.Message;
                return(passModel);
            }
        }
        /// <summary>
        /// Partner Registration
        /// </summary>
        /// <param name="userTableClass"></param>
        /// <returns></returns>
        public RegistrationResponseViewModel AddPartner(UserTableClass userTableClass)
        {
            RegistrationResponseViewModel model = new RegistrationResponseViewModel();

            try
            {
                if (userTableClass != null)
                {
                    using (var db = new Orchard9Entities())
                    {
                        //checking whether email already exists in the database or not
                        var isEmailExist = db.tblUsers.Where(a => a.EmailId == userTableClass.EmailId).FirstOrDefault();

                        if (isEmailExist == null)
                        {
                            db.tblUsers.Add(new tblUser()
                            {
                                EmailId     = userTableClass.EmailId,
                                Name        = userTableClass.Name,
                                Password    = userTableClass.Password,
                                ContactNo   = userTableClass.ContactNo,
                                Gender      = userTableClass.Gender,
                                Address     = userTableClass.Address,
                                ReferralId  = userTableClass.ReferralId,
                                DateOfBirth = userTableClass.DateOfBirth,
                                IsVerified  = false,
                                Role        = 5,
                                IsActive    = true,
                                CreatedDate = DateTime.Now,
                                UserType    = "Normal"
                            });
                            //saving changes to database
                            db.SaveChanges();
                            var data = (from res in db.tblUsers
                                        where res.EmailId == userTableClass.EmailId
                                        select new { res.EmailId, res.UserId }).FirstOrDefault();
                            model.UserId        = data.UserId;
                            model.Email         = data.EmailId;
                            model.StatusMessage = "Registration successfully done. Account activation link has been sent to your Email ID " + model.Email;
                        }
                        else
                        {
                            model.StatusMessage = "Email Already Exist";
                        }
                    }
                }
                else
                {
                    model.StatusMessage = "Input model is empty";
                }
            }
            catch (Exception ex)
            {
                model.StatusMessage = ex.Message;
            }
            return(model);
        }
        /// <summary>
        /// Administrator Login
        /// </summary>
        /// <param name="userLogin"></param>
        /// <returns></returns>
        public LoginResponseViewModel LoginAdmin(UserLogin userLogin)
        {
            LoginResponseViewModel logModel = new LoginResponseViewModel();

            try
            {
                if (userLogin != null)
                {
                    using (var db = new Orchard9Entities())
                    {
                        // checking whether Email id is present in the database or not
                        var v = db.tblUsers.Where(a => a.EmailId == userLogin.EmailId && a.Role == 2).FirstOrDefault();
                        if (v != null)
                        {
                            if (!v.IsVerified)
                            {
                                logModel.StatusMessage = "Email Not Verified";
                                return(logModel);
                            }
                            if (string.Compare(userLogin.Password, v.Password) == 0)
                            {
                                logModel.userLogin = (from res in db.tblUsers
                                                      where res.EmailId == userLogin.EmailId
                                                      select new UserLogin()
                                {
                                    EmailId = res.EmailId,
                                    UserId = res.UserId,
                                    Role = res.Role
                                }).FirstOrDefault();
                                logModel.StatusMessage = "Login Successful";
                                return(logModel);
                            }
                            else
                            {
                                logModel.StatusMessage = "Invalid Password";
                                return(logModel);
                            }
                        }
                        else
                        {
                            logModel.StatusMessage = " User account not found, please register before Login ";
                            return(logModel);
                        }
                    }
                }
                else
                {
                    logModel.StatusMessage = "Input model is empty";
                    return(logModel);
                }
            }
            catch (Exception ex)
            {
                logModel.StatusMessage = ex.Message;
                return(logModel);
            }
        }
Example #9
0
        //Logic for Autosearch according to Initial alphabet.
        public SearchHome searchbooklist(string searchType, string searchText)
        {
            SearchHome model = new SearchHome();

            try
            {
                if (searchType != null && searchText != null)
                {
                    using (var db = new Orchard9Entities())
                    {
                        if (searchType.ToLower() == "author")
                        {
                            model.BookOrAuthorNameOrIsbn = (from res in db.tblBooks
                                                            where res.isactive == true && res.Author.ToLower().Contains(searchText.ToLower())
                                                            select res.Author).Distinct().ToList();
                        }

                        else if (searchType.ToLower() == "book")
                        {
                            model.BookOrAuthorNameOrIsbn = (from res in db.tblBooks
                                                            where res.isactive == true && res.BookName.ToLower().Contains(searchText.ToLower())
                                                            select res.BookName).Distinct().ToList();
                        }
                        else if (searchType.ToLower() == "isbn")
                        {
                            model.BookOrAuthorNameOrIsbn = (from res in db.tblBooks
                                                            where res.isactive == true && res.ISBN.ToLower().Contains(searchText.ToLower())
                                                            select res.ISBN).Distinct().ToList();
                        }
                        if (model.BookOrAuthorNameOrIsbn.Count > 0)
                        {
                            model.StatusMessage = "Success";
                        }
                        else
                        {
                            model.StatusMessage = "No records found";
                        }
                    }
                }
                else
                {
                    model.StatusMessage = "Searchtype and Searchtext are invalid!";
                }
            }
            catch (Exception e)
            {
                model.StatusMessage = e.Message;
            }

            return(model);
        }
        /// <summary>
        /// Google Login
        /// </summary>
        /// <param name="googleLogin"></param>
        /// <returns></returns>
        public LoginResponseViewModel GoogleLogin(GoogleLogin googleLogin)
        {
            LoginResponseViewModel googleModel = new LoginResponseViewModel();

            if (googleLogin != null)
            {
                using (var db = new Orchard9Entities())
                {
                    var gUser  = db.tblUsers.Where(a => a.EmailId == googleLogin.emailaddress).FirstOrDefault();
                    var gUser1 = db.tblUsers.Where(a => a.EmailId == googleLogin.emailaddress && a.IsActive == true).FirstOrDefault();

                    if (gUser1 == null)
                    {
                        googleModel.StatusMessage = "Account is Blocked";
                        return(googleModel);
                    }

                    if (gUser == null)
                    {
                        db.tblUsers.Add(new tblUser()
                        {
                            EmailId     = googleLogin.emailaddress,
                            Name        = googleLogin.givenname,
                            IsVerified  = true,
                            UserType    = "External",
                            Role        = 1,
                            IsActive    = true,
                            CreatedDate = DateTime.Now,
                            DateOfBirth = DateTime.Now.Date
                        });
                        db.SaveChanges();
                        googleModel.StatusMessage = "Login Successful";
                    }
                    googleModel.userLogin = (from res in db.tblUsers
                                             where res.EmailId == googleLogin.emailaddress
                                             select new UserLogin()
                    {
                        EmailId = res.EmailId,
                        UserId = res.UserId
                    }).FirstOrDefault();
                    googleModel.StatusMessage = "Login Successful";
                    return(googleModel);
                }
            }
            else
            {
                googleModel.StatusMessage = "Empty Model";
            }
            return(googleModel);
        }
 public string InvoiceTableUpdate()
 {
     using (var db = new Orchard9Entities())
     {
         try
         {
             var query = db.tblUsers.Where(x => x.IsActive == false).Select(r => r.UserId).Distinct().ToList();
             db.tblInvoices.Where(y => query.Contains((int)y.UserId)).ToList().ForEach(y => y.InvoiceStatus = false);
             db.SaveChanges();
             return("Success");
         }
         catch (Exception e)
         {
             return(e.Message);
         }
     }
 }
Example #12
0
        //fetching details to display the invoice
        public CartStatus Invoice(int UserId)
        {
            CartStatus status = new CartStatus();

            try
            {
                using (var db = new Orchard9Entities())
                {
                    var query = (from cart in db.tblCarts
                                 join book in db.tblBooks on cart.ISBN equals book.ISBN
                                 join user in db.tblUsers on cart.UserId equals user.UserId
                                 where (cart.UserId == UserId) && (cart.PayStatus == true)
                                 select new CartView()
                    {
                        CartId = cart.CartId,
                        UserId = cart.UserId,
                        UserName = user.Name,
                        ISBN = book.ISBN,
                        BookName = book.BookName,
                        BookImageUrl = book.BookImageUrl,
                        Author = book.Author,
                        Publisher = book.Publisher,
                        Category = book.Category,
                        Rating = book.Rating,
                        Description = book.Description,
                        Quantity = cart.Quantity,
                        Price = (book.Price * cart.Quantity)
                    }).ToList();
                    status.statusList = query;
                    if (query.Count == 0)
                    {
                        status.statusMessage = "Invoice unsuccessful";
                    }
                    else
                    {
                        status.statusMessage = "Invoice success";
                    }
                }
            }
            catch (Exception e)
            {
                status.statusMessage = e.Message;
            }
            return(status);
        }
Example #13
0
        public CartStatus Display(int UserId)   //This method is used for getting all the cart details of a user
        {                                       //and display it.
            CartStatus status = new CartStatus();

            try
            {
                using (var db = new Orchard9Entities())
                {
                    if ((from e in db.tblUsers where e.UserId == UserId && e.IsActive == false select e.UserId).ToList().Count > 0)
                    {
                        status.statusMessage = "You are Blocked by Admin";
                    }
                    else
                    {
                        var query = (from cart in db.tblCarts
                                     join book in db.tblBooks on cart.ISBN equals book.ISBN
                                     where (cart.UserId == UserId) && (cart.PayStatus == true)
                                     select new CartView()
                        {
                            CartId = cart.CartId,
                            UserId = cart.UserId,
                            BookName = book.BookName,
                            BookImageUrl = book.BookImageUrl,
                            Quantity = cart.Quantity,
                            Price = (book.Price * cart.Quantity)
                        }).ToList();
                        status.statusList = query;
                        if (query.Count == 0)
                        {
                            status.statusMessage = "No Items in Cart";
                        }
                        else
                        {
                            status.statusMessage = "Items in Cart";
                        }
                    }
                }
            }
            catch (Exception e)
            {
                status.statusMessage = e.Message;
            }
            return(status);
        }
        public string RemoveBook(string ISBN)
        {
            string message;

            try
            {
                using (var db = new Orchard9Entities())
                {
                    db.tblBooks.Where(u => u.ISBN == ISBN).ToList().ForEach(s => s.isactive = false);
                    db.SaveChanges();
                    message = ISBN + " removed ";
                }
            }
            catch (Exception e)
            {
                message = e.Message;
            }
            return(message);
        }
Example #15
0
        public string AddInvoice(InvoiceView invoiceView)
        {
            string msg = "";

            try
            {
                using (var db = new Orchard9Entities())
                {
                    if ((from e in db.tblUsers where e.UserId == invoiceView.UserId && e.IsActive == false select e.UserId).ToList().Count > 0)
                    {
                        return("You are Blocked by Admin");
                    }
                    else
                    {
                        if ((from e in db.tblInvoices
                             where e.UserId == invoiceView.UserId && e.CartId == invoiceView.CartId
                             select e.InvoiceId).ToList().Count > 0)
                        {
                            return("Invoice is generated already");
                        }
                        else
                        {
                            db.tblInvoices.Add(new tblInvoice()
                            {
                                UserId        = invoiceView.UserId,
                                CartId        = invoiceView.CartId,
                                InvoiceStatus = true
                            });

                            db.SaveChanges();

                            return("Invoice Added");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
            }
            return(msg);
        }
Example #16
0
        //deletes the book from wishlist
        public string deleteFromWishList(int wishListId)
        {
            string s = "";

            try
            {
                using (var dbcontext = new Orchard9Entities())
                {
                    tblWishlist test = dbcontext.tblWishlists.Find(wishListId);
                    dbcontext.tblWishlists.Remove(test);
                    dbcontext.SaveChanges();
                    return("deletion successful");
                }
            }
            catch (Exception e)
            {
                s = e.Message;
            }
            return(s);
        }
Example #17
0
        public string Remove(int CartId)  //This method is used for removing a book from the cart.
        {
            string message;

            try
            {
                using (var db = new Orchard9Entities())
                {
                    tblCart a1 = db.tblCarts.Find(CartId);
                    db.tblCarts.Remove(a1);
                    db.SaveChanges();
                    message = CartId + " removed from cart";
                }
            }
            catch (Exception e)
            {
                message = e.Message;
            }
            return(message);
        }
Example #18
0
        //displays all the books in the wishlist
        public WishListStatus displayAllItems(int userid)
        {
            WishListStatus w = new WishListStatus();

            try
            {
                using (var dbcontext = new Orchard9Entities())
                {
                    if ((from e in dbcontext.tblUsers where e.UserId == userid && e.IsActive == false select e.UserId).ToList().Count > 0)
                    {
                        w.statusMessage = "You are Blocked by Admin";
                    }
                    else
                    {
                        var query = (from e in dbcontext.tblWishlists
                                     join d in dbcontext.tblBooks on e.ISBN equals d.ISBN
                                     join x in dbcontext.tblUsers on e.UserId equals x.UserId
                                     where e.UserId == userid
                                     select new WishListModel()
                        {
                            id = e.id, ISBN = e.ISBN, UserId = e.UserId, price = d.Price, Publisher = d.Publisher, Author = d.Author, rating = d.Rating, BookName = d.BookName, BookImageUrl = d.BookImageUrl
                        }).ToList();

                        w.statusList = query;
                        if (query.Count > 0)
                        {
                            w.statusMessage = " Items in Wishlist";
                        }
                        else
                        {
                            w.statusMessage = "no items in wishlist";
                        }
                    }
                }
            }
            catch (Exception e)
            {
                w.statusMessage = e.Message;
            }
            return(w);
        }
Example #19
0
        // this logic is to fetch book details
        public HomePageViewStatus getBookdetails(string ISBN)
        {
            HomePageViewStatus  ob    = new HomePageViewStatus();
            List <HomePageView> model = new List <HomePageView>();

            try
            {
                using (var db = new Orchard9Entities())
                {
                    model = (from book in db.tblBooks
                             where book.isactive == true && ISBN == book.ISBN
                             select new HomePageView
                    {
                        ISBN = book.ISBN,
                        BookImageUrl = book.BookImageUrl,
                        BookName = book.BookName,
                        Author = book.Author,
                        Publisher = book.Publisher,
                        Description = book.Description,
                        Rating = book.Rating,
                        Category = book.Category,
                        Price = book.Price
                    }).ToList();
                    ob.statuslist = model;
                    if (model.Count > 0)
                    {
                        ob.statusMessage = "Success";
                    }
                    else
                    {
                        ob.statusMessage = "No books available";
                    }
                }
            }
            catch (Exception ex)
            {
                ob.statuslist    = model;
                ob.statusMessage = ex.Message;
            }
            return(ob);
        }
Example #20
0
        //adds the book to wishlist
        public string addToWishList(WishListModel wish)
        {
            string s = "";

            try
            {
                using (var dbcontext = new Orchard9Entities())
                {
                    if ((from e in dbcontext.tblUsers where e.UserId == wish.UserId && e.IsActive == false select e.UserId).ToList().Count > 0)
                    {
                        return("You are Blocked by Admin");
                    }
                    else
                    {
                        if ((from e in dbcontext.tblWishlists where e.ISBN == wish.ISBN && e.UserId == wish.UserId select e.id).ToList().Count > 0)
                        {
                            return("Already present");
                        }
                        else
                        {
                            dbcontext.tblWishlists.Add(new tblWishlist()
                            {
                                id           = wish.id,
                                ISBN         = wish.ISBN,
                                UserId       = wish.UserId,
                                CurrentPrice = wish.price
                            });
                            dbcontext.SaveChanges();
                            return("added successfully");
                        }
                    }
                }
            }

            catch (Exception e)
            {
                s = e.Message;
            }
            return(s);
        }
        public UserStatus DisplayUsers()
        {
            UserStatus status = new UserStatus();

            using (var db = new Orchard9Entities())
            {
                var query = (from users in db.tblUsers
                             where users.Role != 2
                             select new UserView()
                {
                    UserId = users.UserId,
                    EmailId = users.EmailId,
                    Name = users.Name,
                    UserType = users.UserType,
                    IsVerified = users.IsVerified,
                    Role = users.Role,
                    IsActive = users.IsActive
                }).ToList();
                status.statusList = query;
            }
            return(status);
        }
        public string ApprovePartner(int UserId)
        {
            string msg = "";

            try
            {
                using (var db = new Orchard9Entities())
                {
                    {
                        db.tblUsers.Where(u => u.UserId == UserId).ToList().ForEach(s => s.Role = 3);
                        db.SaveChanges();
                        msg = "Partner Approved";
                        return(msg);
                    }
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
            }
            return(msg);
        }
Example #23
0
        public string AddToCart(Cart cart)
        {
            string msg = "";

            try
            {
                using (var db = new Orchard9Entities())
                {
                    if ((from e in db.tblUsers where e.UserId == cart.UserId && e.IsActive == false select e.UserId).ToList().Count > 0)
                    {
                        return("You are Blocked by Admin");
                    }
                    else
                    {
                        if ((from e in db.tblCarts where e.ISBN == cart.ISBN && e.UserId == cart.UserId && e.PayStatus == true select e.CartId).ToList().Count > 0)
                        {
                            return("Already Present");
                        }
                        else
                        {
                            db.tblCarts.Add(new tblCart()
                            {
                                ISBN      = cart.ISBN,
                                UserId    = cart.UserId,
                                PayStatus = true,
                                Quantity  = 1
                            });
                            db.SaveChanges();
                            return("Added to Cart");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
            }
            return(msg);
        }
        public string EditBook(BookEditView book)
        {
            string message = "";

            try
            {
                using (var db = new Orchard9Entities())
                {
                    db.tblBooks.Where(b => b.ISBN == book.ISBN).ToList().ForEach(b =>
                    {
                        b.Price = book.Price;
                    });
                    db.SaveChanges();
                    message = book.ISBN + " Price updated";
                }
            }
            catch (Exception e)
            {
                message = e.Message;
            }
            return(message);
        }
        public string UnblockUser(int UserId)
        {
            string msg = "";

            try
            {
                using (var db = new Orchard9Entities())
                {
                    {
                        db.tblUsers.Where(u => u.UserId == UserId).ToList().ForEach(s => s.IsActive = true);
                        db.SaveChanges();
                        msg = "User Unblocked";

                        return(msg);
                    }
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
            }
            return(msg);
        }
        public BookStatus DisplayBooks()
        {
            BookStatus status = new BookStatus();

            using (var db = new Orchard9Entities())
            {
                var query = (from books in db.tblBooks
                             where books.isactive == true
                             select new BookView()
                {
                    ISBN = books.ISBN,
                    BookName = books.BookName,
                    Category = books.Category,
                    Price = books.Price,
                    Rating = books.Rating,
                    Author = books.Author,
                    Publisher = books.Publisher,
                    Description = books.Description,
                    BookImageUrl = books.BookImageUrl
                }).ToList();
                status.statusList = query;
            }
            return(status);
        }
 /// <summary>
 /// User Verifiction
 /// </summary>
 /// <param name="UserId"></param>
 /// <returns></returns>
 public string UserVerification(int UserId)
 {
     try
     {
         using (var db = new Orchard9Entities())
         {
             var verifyUser = db.tblUsers.Where(a => a.UserId == UserId).FirstOrDefault();
             if (verifyUser != null)
             {
                 db.tblUsers.Where(a => a.UserId == UserId).ToList().ForEach(i => i.IsVerified = true);
                 db.SaveChanges();
                 return("User verified successfully");
             }
             else
             {
                 return("User verification Error");
             }
         }
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Example #28
0
        // Logic for search by Author and Bookname and Display complete detail of Book.
        public HomePageViewStatus SearchBookDetails(string searchType, string searchText)
        {
            HomePageViewStatus  ob    = new HomePageViewStatus();
            List <HomePageView> model = new List <HomePageView>();

            try
            {
                if (searchType != null && searchText != null)
                {
                    using (var db = new Orchard9Entities())
                    {
                        if (searchType.ToLower() == "author")
                        {
                            model = (from book in db.tblBooks
                                     where book.isactive == true && book.Author.ToLower().Contains(searchText.ToLower())
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        else if (searchType.ToLower() == "book")
                        {
                            model = (from book in db.tblBooks
                                     where book.isactive == true && book.BookName.ToLower().Contains(searchText.ToLower())
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }

                        else if (searchType.ToLower() == "isbn")
                        {
                            model = (from book in db.tblBooks
                                     where book.isactive == true && book.ISBN.ToLower().Contains(searchText.ToLower())
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        else if (searchType.ToLower() == "initial")
                        {
                            model = (from book in db.tblBooks
                                     where book.isactive == true
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                    }

                    ob.statuslist = model;
                    if (model.Count > 0)
                    {
                        ob.statusMessage = "Success";
                    }
                    else
                    {
                        ob.statusMessage = "No record found.!";
                    }
                }
                else
                {
                    ob.statusMessage = "Searchtype and Searchtext are invalid!";
                }
            }
            catch (Exception ex)
            {
                ob.statuslist    = model;
                ob.statusMessage = ex.Message;
            }

            return(ob);
        }
        public string AddBook(BookView book)
        {
            string msg = "";

            try
            {
                using (var db = new Orchard9Entities())
                {
                    if ((from e in db.tblUsers where e.UserId == book.UserId && e.IsActive == false select e.UserId).ToList().Count > 0)
                    {
                        return("You are Blocked by Admin");
                    }
                    else if ((from e in db.tblBooks where (e.ISBN == book.ISBN && e.isactive == false) select e.ISBN).ToList().Count > 0)
                    {
                        db.tblBooks.Where(b => b.ISBN == book.ISBN).ToList().ForEach(b =>
                        {
                            b.BookName     = book.BookName;
                            b.Category     = book.Category;
                            b.Price        = book.Price;
                            b.Rating       = book.Rating;
                            b.Author       = book.Author;
                            b.Publisher    = book.Publisher;
                            b.Description  = book.Description;
                            b.BookImageUrl = book.BookImageUrl;
                            b.isactive     = true;
                            b.createddate  = System.DateTime.Now;
                        });
                        db.SaveChanges();
                        return("Book updated");
                    }

                    else if ((from e in db.tblBooks where e.ISBN == book.ISBN || (e.BookName == book.BookName && e.Author == book.Author) select e.ISBN).ToList().Count > 0)
                    {
                        return("Book Already Exists");
                    }
                    else
                    {
                        db.tblBooks.Add(new tblBook()
                        {
                            ISBN         = book.ISBN,
                            BookName     = book.BookName,
                            Category     = book.Category,
                            Price        = book.Price,
                            Rating       = book.Rating,
                            Author       = book.Author,
                            Publisher    = book.Publisher,
                            Description  = book.Description,
                            BookImageUrl = book.BookImageUrl,
                            isactive     = true,
                            createddate  = System.DateTime.Now
                        });
                        db.SaveChanges();
                        return("New Book Added");
                    }
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
            }
            return(msg);
        }
Example #30
0
//this logic is used to perform filter operation
        public HomePageViewStatus filtermanage(HomePage homepage)
        {
            HomePageViewStatus  ob    = new HomePageViewStatus();
            List <HomePageView> model = new List <HomePageView>();

            try
            {
                using (var db = new Orchard9Entities())
                {
                    var result = (from book in db.tblBooks
                                  where book.isactive == true
                                  select new HomePageView
                    {
                        ISBN = book.ISBN,
                        BookImageUrl = book.BookImageUrl,
                        BookName = book.BookName,
                        Author = book.Author,
                        Publisher = book.Publisher,
                        Rating = book.Rating,
                        Category = book.Category,
                        Price = book.Price
                    }).ToList();
                    if (result.Count > 0)
                    {
                        #region Search criteria
                        if (homepage.searchType != null && homepage.searchText != null)
                        {
                            if (homepage.searchType.ToLower() == "author")
                            {
                                result = result.Where(s => s.Author.ToLower().Contains(homepage.searchText.ToLower())).ToList();
                            }
                            else if (homepage.searchType.ToLower() == "book")
                            {
                                result = result.Where(s => s.BookName.ToLower().Contains(homepage.searchText.ToLower())).ToList();
                            }
                        }
                        #endregion
                        #region Filter Criteria
                        if (homepage.Author == null && homepage.Category == null && homepage.Rating == null)
                        {
                            model = (from book in result
                                     where (book.Price >= homepage.PriceFrom && book.Price <= homepage.PriceTo)
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        else if (homepage.Author != null && homepage.Category == null && homepage.Rating == null)
                        {
                            model = (from book in result
                                     where (book.Price >= homepage.PriceFrom && book.Price <= homepage.PriceTo) &&
                                     homepage.Author.Contains(book.Author)
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        else if (homepage.Author != null && homepage.Category != null && homepage.Rating == null)
                        {
                            model = (from book in result
                                     where (book.Price >= homepage.PriceFrom && book.Price <= homepage.PriceTo) &&
                                     homepage.Author.Contains(book.Author) && homepage.Category.Contains(book.Category)
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        else if (homepage.Author != null && homepage.Category == null && homepage.Rating != null)
                        {
                            model = (from book in result
                                     where (book.Price >= homepage.PriceFrom && book.Price <= homepage.PriceTo) &&
                                     homepage.Author.Contains(book.Author) && homepage.Rating.Contains(book.Rating)
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        else if (homepage.Author == null && homepage.Category != null && homepage.Rating == null)
                        {
                            model = (from book in result
                                     where (book.Price >= homepage.PriceFrom && book.Price <= homepage.PriceTo) &&
                                     homepage.Category.Contains(book.Category)
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        else if (homepage.Author == null && homepage.Category != null && homepage.Rating != null)
                        {
                            model = (from book in result
                                     where (book.Price >= homepage.PriceFrom && book.Price <= homepage.PriceTo) &&
                                     homepage.Category.Contains(book.Category) && homepage.Rating.Contains(book.Rating)
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        else if (homepage.Author == null && homepage.Category == null && homepage.Rating != null)
                        {
                            model = (from book in result
                                     where (book.Price >= homepage.PriceFrom && book.Price <= homepage.PriceTo) &&
                                     homepage.Rating.Contains(book.Rating)
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        else if (homepage.Author != null && homepage.Category != null && homepage.Rating != null)
                        {
                            model = (from book in result
                                     where (book.Price >= homepage.PriceFrom && book.Price <= homepage.PriceTo) &&
                                     homepage.Author.Contains(book.Author) && homepage.Category.Contains(book.Category) && homepage.Rating.Contains(book.Rating)
                                     select new HomePageView
                            {
                                ISBN = book.ISBN,
                                BookImageUrl = book.BookImageUrl,
                                BookName = book.BookName,
                                Author = book.Author,
                                Publisher = book.Publisher,
                                Rating = book.Rating,
                                Category = book.Category,
                                Price = book.Price
                            }).ToList();
                        }
                        #endregion

                        ob.statuslist = model;
                        if (model.Count > 0)
                        {
                            ob.statusMessage = "Success";
                        }
                        else
                        {
                            ob.statusMessage = "No books avialble for your selected filters";
                        }
                    }
                    else
                    {
                        ob.statusMessage = "No books avialble in DB";
                    }
                }
            }
            catch (Exception ex)
            {
                ob.statuslist    = model;
                ob.statusMessage = ex.Message;
            }
            return(ob);
        }