public bool DeleteProduct(int pid)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         var size    = context.SizeTable.Where(x => x.ProductID == pid).ToList();
         var product = context.ProductTable.FirstOrDefault(x => x.ProductID == pid);
         var cart    = context.CartTable.FirstOrDefault(x => x.PID == pid);
         if (size != null && product != null)
         {
             if (cart != null)
             {
                 context.CartTable.Remove(cart);
                 context.SaveChanges();
             }
             foreach (var i in size)
             {
                 context.SizeTable.Remove(i);
             }
             context.SaveChanges();
             context.ProductTable.Remove(product);
             context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
        public int OrderNow(int uid, int pid, OrderModel model)
        {
            using (ShoppingELFEntities context = new ShoppingELFEntities())
            {
                UserTable user = new UserTable();
                user = context.UserTable.FirstOrDefault(m => m.UserID == uid);
                SizeTable st = new SizeTable();
                st = context.SizeTable.FirstOrDefault(m => m.PID == pid);
                if (st.productQuantity > 0)
                {
                    OrderTable ot = new OrderTable()
                    {
                        UserID          = uid,
                        PID             = pid,
                        productBrand    = st.ProductTable.productBrand,
                        ProductName     = st.ProductTable.productName,
                        productPicture  = st.ProductTable.picture1,
                        productPrice    = st.productPrice,
                        productSize     = st.productSize,
                        productQuantity = 1
                    };
                    st.productQuantity -= 1;
                    context.OrderTable.Add(ot);
                    context.SaveChanges();

                    SizeTable seller = new SizeTable();
                    seller = context.SizeTable.FirstOrDefault(x => x.PID == pid);
                    ProductTable pp = new ProductTable();
                    pp = context.ProductTable.FirstOrDefault(m => m.ProductID == seller.ProductID);

                    SoldTable soldt = new SoldTable()
                    {
                        SellerID        = pp.SellerID,
                        productName     = st.ProductTable.productName,
                        productBrand    = st.ProductTable.productBrand,
                        productPrice    = st.productPrice,
                        productQuantity = 1,
                        productSize     = st.productSize,
                        productPicture  = st.ProductTable.picture1,
                        PID             = pid,
                        UserName        = user.email
                    };
                    context.SoldTable.Add(soldt);
                    context.SaveChanges();

                    return(1);
                }
                else
                {
                    return(0);
                }
            }
        }
Exemplo n.º 3
0
 public HttpResponseMessage VerifyAccount([FromUri] string id)
 {
     //bool status = false;
     try
     {
         using (ShoppingELFEntities context = new ShoppingELFEntities())
         {
             UserTable us = new UserTable();
             var       v  = context.UserTable.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
             if (v != null)
             {
                 us.IsEmailVerified = true;
                 v.IsEmailVerified  = Convert.ToBoolean(us.IsEmailVerified);
                 context.SaveChanges();
                 //status = true;
                 return(Request.CreateResponse(HttpStatusCode.OK, "Your account has been successfully verified, Please go back on the login page to continue shopping with us<br/>Thank You!!!<br/>Team ShoppingELF"));
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound, "Unable to activate account"));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Exemplo n.º 4
0
 public IHttpActionResult ResetPassword(ChangePasswordModel model)
 {
     try
     {
         using (ShoppingELFEntities context = new ShoppingELFEntities())
         {
             var user = context.UserTable.Where(x => x.email == model.EmailID).FirstOrDefault();
             if (user != null && Convert.ToBoolean(user.IsResetPassword))
             {
                 user.password          = Crypto.Hash(model.NewPassword);
                 user.ResetPasswordCode = "";
                 user.IsResetPassword   = false;
                 context.Configuration.ValidateOnSaveEnabled = false;
                 context.SaveChanges();
                 return(Ok("New Password updated successfully"));
             }
             else
             {
                 return(Ok("unable to reach account please try again"));
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 5
0
        public IHttpActionResult ResetPassword(string ID)
        {
            try
            {
                using (ShoppingELFEntities context = new ShoppingELFEntities())
                {
                    var user = context.UserTable.Where(x => x.ResetPasswordCode == ID).FirstOrDefault();
                    if (user != null)
                    {
                        ChangePasswordModel model = new ChangePasswordModel();
                        user.IsResetPassword = true;

                        context.SaveChanges();
                        return(Ok("Account Verified"));
                    }
                    else
                    {
                        return(Ok("Something Went Wrong"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 6
0
 public IHttpActionResult ForgotPassword(ChangePasswordModel model)
 {
     try
     {
         using (ShoppingELFEntities context = new ShoppingELFEntities())
         {
             var acc = context.UserTable.Where(x => x.email == model.EmailID).FirstOrDefault();
             if (acc != null)
             {
                 string ResetCode = Guid.NewGuid().ToString();
                 EmailVerification(acc.UserID, acc.email, ResetCode, "ResetPassword");
                 acc.ResetPasswordCode = ResetCode;
                 context.Configuration.ValidateOnSaveEnabled = false;
                 context.SaveChanges();
                 return(Ok("Reset password code has been sent to your email"));
             }
             else
             {
                 return(Ok("Account Not found"));
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 7
0
 public int ChangePassword(int uid, ChangePasswordModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         var user = context.UserTable.FirstOrDefault(x => x.UserID == uid);
         if (user != null)
         {
             string oldPassword = Crypto.Hash(model.oldPassword);
             string newPassword = Crypto.Hash(model.NewPassword);
             if (oldPassword != user.password)
             {
                 return(1);
             }
             else if (newPassword == user.password)
             {
                 return(4);
             }
             else
             {
                 user.password = newPassword;
                 context.SaveChanges();
                 return(2);
             }
             //return 0;
         }
         else
         {
             return(3);
         }
     }
 }
Exemplo n.º 8
0
 public bool EnterDetails(int sid, SellerDetailsModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         SellerDetailsTable sdt = new SellerDetailsTable()
         {
             AddressLine1      = model.AddressLine1,
             AddressLine2      = model.AddressLine2,
             pincode           = model.pincode,
             state             = model.state,
             city              = model.city,
             AccountHolderName = model.AccountHolderName,
             accountNumber     = model.accountNumber,
             accountType       = model.accountType,
             IFSCCode          = model.IFSCCode,
             ShippingFee       = model.ShippingFee,
             GSTNumber         = model.GSTNumber,
             PANCardNumber     = model.PANCardNumber,
             SellerID          = sid
         };
         context.SellerDetailsTable.Add(sdt);
         context.SaveChanges();
         return(true);
     }
 }
Exemplo n.º 9
0
 public IHttpActionResult EnterOTP(int sid, SellerModel model)
 {
     try
     {
         using (ShoppingELFEntities context = new ShoppingELFEntities())
         {
             SellerTable seller = new SellerTable();
             seller = context.SellerTable.FirstOrDefault(m => m.SellerID == sid);
             bool x = new SellerAccountModel().IsOTPExpired(sid);
             if (seller.OTP == model.OTP && !x)
             {
                 seller.IsAccountVerified = true;
                 context.SaveChanges();
                 return(Ok(TokenManager.GenerateToken(seller.email)));
             }
             else
             {
                 return(BadRequest("Please enter a valid OTP"));
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 10
0
 public bool EditDetails(int sid, SellerDetailsModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         SellerDetailsTable sdt = new SellerDetailsTable();
         sdt = context.SellerDetailsTable.FirstOrDefault(x => x.SellerID == sid);
         if (sdt != null)
         {
             sdt.AddressLine1      = model.AddressLine1;
             sdt.AddressLine2      = model.AddressLine2;
             sdt.pincode           = model.pincode;
             sdt.state             = model.state;
             sdt.city              = model.city;
             sdt.AccountHolderName = model.AccountHolderName;
             sdt.accountNumber     = model.accountNumber;
             sdt.accountType       = model.accountType;
             sdt.ShippingFee       = model.ShippingFee;
             sdt.GSTNumber         = model.GSTNumber;
             sdt.PANCardNumber     = model.PANCardNumber;
             context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 11
0
 public void OTPSentTime(string Email)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         SellerTable st = new SellerTable();
         st             = context.SellerTable.FirstOrDefault(m => m.email == Email);
         st.OTPSentTIme = DateTime.Now.TimeOfDay.Minutes;
         context.SaveChanges();
     }
 }
 public int ImageUpload(int pid, int picimg, string imgpath)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         ProductTable pt = new ProductTable();
         pt = context.ProductTable.FirstOrDefault(m => m.ProductID == pid);
         if (pt != null)
         {
             if (picimg == 1)
             {
                 pt.picture1 = imgpath;
                 context.SaveChanges();
                 return(1);
             }
             else if (picimg == 2)
             {
                 pt.picture2 = imgpath;
                 context.SaveChanges();
                 return(1);
             }
             else if (picimg == 3)
             {
                 pt.picture3 = imgpath;
                 context.SaveChanges();
                 return(1);
             }
             else if (picimg == 4)
             {
                 pt.picture4 = imgpath;
                 context.SaveChanges();
                 return(1);
             }
             else
             {
                 return(0);
             }
         }
         else
         {
             return(2);
         }
     }
 }
Exemplo n.º 13
0
 public void ResendOTP(int sid)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         SellerTable st = new SellerTable();
         st = context.SellerTable.FirstOrDefault(m => m.SellerID == sid);
         string otp = GenerateRandomNumber();
         st.OTP         = otp;
         st.OTPSentTIme = DateTime.Now.TimeOfDay.Minutes;
         context.SaveChanges();
     }
 }
Exemplo n.º 14
0
 public void ClearCart(int uid)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         var querry = context.CartTable.Where(m => m.UserID == uid).ToList();
         foreach (var q in querry)
         {
             context.CartTable.Remove(q);
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 15
0
        public void AddSeller(SellerTable seller)
        {
            SellerTable st = new SellerTable();

            using (ShoppingELFEntities db = new ShoppingELFEntities())
            {
                seller.OTP      = Convert.ToString(GenerateRandomNumber());
                seller.Role     = "Seller";
                seller.password = Crypto.Hash(seller.password);
                db.SellerTable.Add(seller);
                db.SaveChanges();
            }
        }
Exemplo n.º 16
0
        public void AddUser(UserTable user)
        {
            UserTable us = new UserTable();

            using (ShoppingELFEntities db = new ShoppingELFEntities())
            {
                us.ActivationCode   = Guid.NewGuid();
                user.ActivationCode = us.ActivationCode;
                user.Role           = "User";
                user.password       = Crypto.Hash(user.password);
                db.UserTable.Add(user);
                db.SaveChanges();
            }
        }
 public bool DeleteSize(int pid)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         var size = context.SizeTable.FirstOrDefault(x => x.PID == pid);
         if (size != null)
         {
             var order = context.CartTable.FirstOrDefault(x => x.PID == pid);
             if (order != null)
             {
                 context.CartTable.Remove(order);
                 context.SaveChanges();
             }
             context.SizeTable.Remove(size);
             context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 18
0
 public int AddToCart(int uid, int pid)
 {
     using (var context = new ShoppingELFEntities())
     {
         CartTable ct = new CartTable()
         {
             PID      = pid,
             UserID   = uid,
             Quantity = 1
         };
         context.CartTable.Add(ct);
         context.SaveChanges();
         return(ct.CartID);
     }
 }
Exemplo n.º 19
0
 public int RemoveFromCart(int cid)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         var result = context.CartTable.FirstOrDefault(x => x.CartID == cid);
         if (result != null)
         {
             context.CartTable.Remove(result);
             context.SaveChanges();
             return(1);
         }
         else
         {
             return(0);
         }
     }
 }
 public bool AddProductSize(int pid, SizeModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         SizeTable st = new SizeTable()
         {
             ProductID       = pid,
             productSize     = model.productSize,
             productPrice    = model.productPrice,
             productQuantity = model.productQuantity
         };
         context.SizeTable.Add(st);
         context.SaveChanges();
         SelectMininmumPrice(pid);
     }
     return(true);
 }
Exemplo n.º 21
0
 public bool UpdateCartModel(int cid, CartModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         var cart = context.CartTable.FirstOrDefault(m => m.CartID == cid);
         if (cart != null)
         {
             cart.Quantity = model.Quantity;
             context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 22
0
 public void AddAddress(int uid, AddressModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         AddressTable at = new AddressTable()
         {
             AddressLine1 = model.AddressLine1,
             AddressLine2 = model.AddressLine2,
             Pincode      = model.Pincode,
             State        = model.State,
             city         = model.city,
             UserID       = uid
         };
         context.AddressTable.Add(at);
         context.SaveChanges();
     }
 }
Exemplo n.º 23
0
 public bool EditAccount(int uid, UserModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         var user = context.UserTable.FirstOrDefault(x => x.UserID == uid);
         if (user != null)
         {
             user.phoneNumber = model.phoneNumber;
             user.yourName    = model.yourName;
             context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
 public int AddProduct(int subid, int sid, int suitid, ProductModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         ProductTable pt = new ProductTable()
         {
             productName    = model.productName,
             productBrand   = model.productBrand,
             productDetails = model.productDetails,
             SubCategoryID  = subid,
             SellerID       = sid,
             SuitableID     = suitid
         };
         context.ProductTable.Add(pt);
         context.SaveChanges();
         return(pt.ProductID);
     }
 }
 public bool EditProduct(int pid, SizeModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         var product = context.SizeTable.FirstOrDefault(x => x.PID == pid);
         if (product != null)
         {
             product.productPrice    = model.productPrice;
             product.productQuantity = model.productQuantity;
             product.productSize     = model.productSize;
             context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
        public void SelectMininmumPrice(int pid)
        {
            using (ShoppingELFEntities context = new ShoppingELFEntities())
            {
                ProductTable pt = new ProductTable();
                SizeTable    st = new SizeTable();
                pt = context.ProductTable.FirstOrDefault(x => x.ProductID == pid);

                var SizeList  = context.SizeTable.Where(m => m.ProductID == pid).ToList();
                int min_price = 2147483647;
                foreach (var i in SizeList)
                {
                    if (i.productPrice < min_price)
                    {
                        min_price = i.productPrice;
                    }
                }
                pt.price = min_price;
                context.SaveChanges();
            }
        }
Exemplo n.º 27
0
 public bool EditAddress(int uid, AddressModel model)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         var Address = context.AddressTable.FirstOrDefault(x => x.UserID == uid);
         if (Address != null)
         {
             Address.AddressLine1 = model.AddressLine1;
             Address.AddressLine2 = model.AddressLine2;
             Address.city         = model.city;
             Address.Pincode      = model.Pincode;
             Address.State        = model.State;
             context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 28
0
        public int AddFromCartToOrder(int uid)
        {
            using (ShoppingELFEntities context = new ShoppingELFEntities())
            {
                CartTable ct   = new CartTable();
                SizeTable st   = new SizeTable();
                UserTable user = new UserTable();
                user = context.UserTable.FirstOrDefault(m => m.UserID == uid);
                var cart      = context.CartTable.Where(m => m.UserID == uid).ToList();
                var cartitems = context.CartTable.Where(m => m.UserID == uid).ToList();
                if (cart.Count > 0)
                {
                    foreach (var i in cartitems)
                    {
                        st = context.SizeTable.FirstOrDefault(x => x.PID == i.PID);
                        if (st.productQuantity > 0)
                        {
                            OrderTable ot = new OrderTable()
                            {
                                UserID          = uid,
                                productBrand    = i.SizeTable.ProductTable.productBrand,
                                ProductName     = i.SizeTable.ProductTable.productName,
                                productPicture  = i.SizeTable.ProductTable.picture1,
                                productPrice    = i.SizeTable.productPrice,
                                productSize     = i.SizeTable.productSize,
                                productQuantity = i.Quantity,
                                PID             = i.PID,
                            };

                            st.productQuantity -= i.Quantity;
                            context.OrderTable.Add(ot);
                            context.SaveChanges();

                            ProductTable seller = new ProductTable();
                            seller = context.ProductTable.FirstOrDefault(x => x.ProductID == i.SizeTable.ProductID);


                            SoldTable soldt = new SoldTable()
                            {
                                SellerID        = seller.SellerID,
                                productName     = i.SizeTable.ProductTable.productName,
                                productBrand    = i.SizeTable.ProductTable.productBrand,
                                productPrice    = i.SizeTable.productPrice,
                                productQuantity = i.SizeTable.productQuantity,
                                productSize     = i.SizeTable.productSize,
                                productPicture  = i.SizeTable.ProductTable.picture1,
                                PID             = i.PID,
                                UserName        = user.email
                            };
                            context.SoldTable.Add(soldt);
                            context.SaveChanges();
                            //return 1;
                        }
                        else
                        {
                            return(2);
                        }
                    }
                    return(3);
                }
                else
                {
                    return(0);
                }
            }
        }