/// <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);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
        /// <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>
        /// 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);
         }
     }
 }
        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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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 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);
        }
        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);
        }
 /// <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);
     }
 }
        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);
        }
        public PriceStatus modifybook(WishListModel wish)
        {
            string s = "";

            PriceStatus pr = new PriceStatus();



            try
            {
                using (var dbcontext = new Orchard9Entities())
                {
                    double?amount = 0;
                    if ((from d in dbcontext.tblWishlists where d.ISBN == wish.ISBN select d).Count() > 0)
                    {
                        amount = (from d in dbcontext.tblWishlists where d.ISBN == wish.ISBN select d.CurrentPrice).FirstOrDefault();
                    }
                    else
                    {
                        amount = (from d in dbcontext.tblBooks where d.ISBN == wish.ISBN select d.Price).FirstOrDefault();
                    }
                    var dis = Convert.ToDouble(wish.price);

                    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 == x.UserId && wish.ISBN == d.ISBN
                                 select new PriceModel()
                    {
                        mailid = x.EmailId
                    }).ToList();



                    if ((from d in dbcontext.tblBooks where d.ISBN == wish.ISBN select d.Price).ToList().Count == 0)
                    {
                        pr.statusMessage = "This book does not exist";

                        return(pr);
                    }
                    if (amount == dis)
                    {
                        pr.statusMessage = "no changes";
                        pr.statusList    = query;
                        pr.changedPrice  = 0;
                        pr.bookName      = wish.BookName;
                    }
                    else if (amount > dis)

                    {
                        pr.changedPrice  = amount - dis;
                        pr.statusList    = query;
                        pr.statusMessage = "reduced";
                        pr.bookName      = wish.BookName;
                    }
                    else
                    {
                        pr.changedPrice  = dis - amount;
                        pr.statusList    = query;
                        pr.bookName      = wish.BookName;
                        pr.statusMessage = "increased";
                    }



                    dbcontext.tblBooks.Where(h => h.ISBN == wish.ISBN).ToList().ForEach(h =>
                    {
                        h.Price        = wish.price;
                        h.Publisher    = wish.Publisher;
                        h.Author       = wish.Author;
                        h.Rating       = wish.rating;
                        h.BookName     = wish.BookName;
                        h.Description  = "jj";
                        h.Category     = "hhh";
                        h.isactive     = true;
                        h.BookImageUrl = wish.BookImageUrl;
                    });
                    dbcontext.tblWishlists.Where(h => h.ISBN == wish.ISBN).ToList().ForEach(h =>
                    {
                        h.CurrentPrice = wish.price;
                    });
                    dbcontext.SaveChanges();
                }
            }

            catch (Exception e)
            {
                s = e.Message;
                pr.statusMessage = s;
            }
            return(pr);
        }