Exemplo n.º 1
0
        public HttpResponseMessage AddProductSize(int pid, SizeModel model, string token)
        {
            try
            {
                using (ShoppingELFEntities context = new ShoppingELFEntities())
                {
                    SellerTable seller   = new SellerTable();
                    string      username = TokenManager.ValidateToken(token);
                    seller = context.SellerTable.FirstOrDefault(x => x.email == username);

                    if (seller != null && seller.Role == "Seller")
                    {
                        bool x = new ProductRepository().AddProductSize(pid, model);
                        if (x)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, "Product Size Added"));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Their is some problem adding the product size"));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Access to this page is denied"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public void Transaction_Effective()
        {
            var testSeller = new SellerTable()
            {
                Name = "Test"
            };

            using (var db = FakeBookingSystem.Database.Mem.Database.Open())
            {
                using (var transaction = db.OpenTransaction(IsolationLevel.Serializable))
                {
                    db.Insert(testSeller);
                    // Note transaction.Commit(); not called
                }

                var count = db.Select <SellerTable>().Where(x => x.Id == testSeller.Id).Count();

                // As transaction did not succeed the record should not have been written
                Assert.Equal(0, count);

                // Without transaction should be able to get what was written
                var         testSellerId = db.Insert(testSeller, true);
                SellerTable seller       = db.SingleById <SellerTable>(testSellerId);

                Assert.Equal("Test", seller.Name);
            }
        }
Exemplo n.º 3
0
        public HttpResponseMessage EditProduct(int pid, SizeModel model, string token)
        {
            try
            {
                using (ShoppingELFEntities context = new ShoppingELFEntities())
                {
                    SellerTable seller   = new SellerTable();
                    string      username = TokenManager.ValidateToken(token);
                    seller = context.SellerTable.FirstOrDefault(x => x.email == username);

                    if (seller != null && seller.Role == "Seller")
                    {
                        bool x = new ProductRepository().EditProduct(pid, model);
                        if (x)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, "Product Details Updated successfully"));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Something Went Wrong , please try again later"));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Access to this page is denied"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 4
0
        public HttpResponseMessage Login([FromBody] SellerTable seller)
        {
            try
            {
                var         y        = new SellerAccountModel().verification(seller.email);
                var         password = new SellerAccountModel().Password(seller.email);
                SellerTable u        = new SellerAccountModel().GetSeller(seller.email);

                if (u == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound,
                                                  "The Account was not found."));
                }
                string pass        = Crypto.Hash(seller.password);
                bool   credentials = pass.Equals(password);
                if (credentials && y)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, TokenManager.GenerateToken(seller.email)));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.Forbidden, "The email/password combination was wrong."));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 5
0
        public HttpResponseMessage DeleteProduct(int pid, string token)
        {
            try
            {
                using (ShoppingELFEntities context = new ShoppingELFEntities())
                {
                    SellerTable seller   = new SellerTable();
                    string      username = TokenManager.ValidateToken(token);
                    seller = context.SellerTable.FirstOrDefault(x => x.email == username);

                    if (seller != null && seller.Role == "Seller")
                    {
                        bool x = new ProductRepository().DeleteProduct(pid);
                        if (x)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, "Product deleted successfully"));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.NotFound, "Unable to delete product"));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Access to this page is denied"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 6
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.º 7
0
        public IHttpActionResult ShowOrderedItems(string token)
        {
            try
            {
                using (ShoppingELFEntities context = new ShoppingELFEntities())
                {
                    SellerTable seller   = new SellerTable();
                    string      username = TokenManager.ValidateToken(token);
                    seller = context.SellerTable.FirstOrDefault(x => x.email == username);

                    if (seller != null && seller.Role == "Seller")
                    {
                        var x = new SellerModel().ShowOrderedItems(seller.SellerID);
                        return(Ok(x));
                    }
                    else
                    {
                        return(Unauthorized());
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 8
0
        public HttpResponseMessage ShowSellerProductSize(int pid, string token)
        {
            try
            {
                using (ShoppingELFEntities context = new ShoppingELFEntities())
                {
                    SellerTable seller   = new SellerTable();
                    string      username = TokenManager.ValidateToken(token);
                    seller = context.SellerTable.FirstOrDefault(x => x.email == username);

                    if (seller != null && seller.Role == "Seller")
                    {
                        var x = new ProductRepository().ShowSellerProductSize(pid);
                        return(Request.CreateResponse(HttpStatusCode.OK, x));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.Forbidden, "Access to this page is denied"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 9
0
        public IHttpActionResult EditDetails(SellerDetailsModel model, string token)
        {
            try
            {
                using (ShoppingELFEntities context = new ShoppingELFEntities())
                {
                    SellerTable seller   = new SellerTable();
                    string      username = TokenManager.ValidateToken(token);
                    seller = context.SellerTable.FirstOrDefault(x => x.email == username);

                    if (seller != null && seller.Role == "Seller")
                    {
                        bool x = new SellerModel().EditDetails(seller.SellerID, model);
                        if (x)
                        {
                            return(Ok("Details Edited Successfully"));
                        }
                        else
                        {
                            return(Ok("Something went wrong please try again later"));
                        }
                    }
                    else
                    {
                        return(Unauthorized());
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 10
0
        public HttpResponseMessage AddProduct(int subid, int suitid, ProductModel model, string token)
        {
            try
            {
                using (ShoppingELFEntities context = new ShoppingELFEntities())
                {
                    SellerTable seller   = new SellerTable();
                    string      username = TokenManager.ValidateToken(token);
                    seller = context.SellerTable.FirstOrDefault(x => x.email == username);

                    if (seller != null && seller.Role == "Seller")
                    {
                        int x = new ProductRepository().AddProduct(subid, seller.SellerID, suitid, model);
                        return(Request.CreateResponse(HttpStatusCode.OK, x));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Access to this page is denied"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
 public ActionResult addNewSeller([Bind(Include = "FirstName,LastName,Address,PhoneNumber,EmailAddress")] SellerTable SellerRegistration)
 {
     using (OREDatabaseEntities1 db = new OREDatabaseEntities1())
     {
         db.SellerTables.Add(SellerRegistration);
         db.SaveChanges();
     }
     return(View(SellerRegistration));
 }
Exemplo n.º 12
0
        public bool verification(string Email)
        {
            ShoppingELFEntities context = new ShoppingELFEntities();
            SellerTable         Fac     = new SellerTable();

            Fac = context.SellerTable.SingleOrDefault(m => m.email == Email);
            var y = Convert.ToBoolean(Fac.IsAccountVerified);

            return(y);
        }
Exemplo n.º 13
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();
     }
 }
Exemplo n.º 14
0
        public string Password(string Email)
        {
            ShoppingELFEntities context = new ShoppingELFEntities();
            SellerTable         us      = new SellerTable();

            us = context.SellerTable.SingleOrDefault(x => x.email == Email);
            string pass = Convert.ToString(us.password);

            return(pass);
        }
Exemplo n.º 15
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.º 16
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();
            }
        }
 public string regSeller(SellerTable model)
 {
     try
     {
         OREDatabaseEntities1 db1 = new OREDatabaseEntities1();
         db1.SellerTables.Add(model);
         db1.SaveChanges();
         return("Done");
     }
     catch
     {
         return("Invalid");
     }
 }
Exemplo n.º 18
0
 public bool IsOTPExpired(int sid)
 {
     using (ShoppingELFEntities context = new ShoppingELFEntities())
     {
         SellerTable st = new SellerTable();
         st = context.SellerTable.FirstOrDefault(m => m.SellerID == sid);
         if ((DateTime.Now.TimeOfDay.Minutes - st.OTPSentTIme) > 3)
         {
             st.OTP = "NULL";
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 19
0
 public IHttpActionResult ResendOTP(int sid)
 {
     try
     {
         using (ShoppingELFEntities context = new ShoppingELFEntities())
         {
             new SellerAccountModel().ResendOTP(sid);
             SellerTable st = new SellerTable();
             st = context.SellerTable.FirstOrDefault(m => m.SellerID == sid);
             EmailVerification(sid, st.email, st.OTP);
             return(Ok("OTP sent sucessfully"));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 20
0
        public IHttpActionResult ChangePassword(ChangePasswordModel model, string token)
        {
            try
            {
                using (ShoppingELFEntities context = new ShoppingELFEntities())
                {
                    SellerTable seller   = new SellerTable();
                    string      username = TokenManager.ValidateToken(token);
                    seller = context.SellerTable.FirstOrDefault(m => m.email == username);

                    if (seller != null && seller.Role == "Seller")
                    {
                        int x = new SellerModel().ChangePassword(seller.SellerID, model);
                        if (x == 1)
                        {
                            return(Ok("Please enter correct old password"));
                        }
                        else if (x == 4)
                        {
                            return(Ok("new password cannot be equal to old password"));
                        }
                        else if (x == 2)
                        {
                            return(Ok("Password Updated successfully"));
                        }
                        else
                        {
                            return(BadRequest("Something went wrong"));
                        }
                    }
                    else
                    {
                        return(Unauthorized());
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 21
0
 public HttpResponseMessage PostSignup([FromBody] SellerTable seller)
 {
     try
     {
         var x = new SellerAccountModel().IsSellerExist(seller.email);
         if (x)
         {
             var timeSent1 = DateTime.Now.TimeOfDay.Seconds;
             return(Request.CreateResponse(HttpStatusCode.Forbidden, "Account already exist"));
         }
         else
         {
             new SellerAccountModel().AddSeller(seller);
             EmailVerification(seller.SellerID, seller.email, seller.OTP);
             new SellerAccountModel().OTPSentTime(seller.email);
             return(Request.CreateResponse(HttpStatusCode.Created, seller.SellerID));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Exemplo n.º 22
0
        public IHttpActionResult PostUserImage(int pid, int picimg, string token)
        {
            using (ShoppingELFEntities context = new ShoppingELFEntities())
            {
                SellerTable seller   = new SellerTable();
                string      username = TokenManager.ValidateToken(token);
                seller = context.SellerTable.FirstOrDefault(m => m.email == username);
                if (seller != null && seller.Role == "Seller")
                {
                    Dictionary <string, object> dict = new Dictionary <string, object>();
                    try
                    {
                        var httpRequest = HttpContext.Current.Request;
                        foreach (string file in httpRequest.Files)
                        {
                            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);
                            var postedFile = httpRequest.Files[file];
                            if (postedFile != null && postedFile.ContentLength > 0)
                            {
                                IList <string> AllowedFileExtensions = new List <string> {
                                    ".jpg", ".gif", ".png", ".jpeg"
                                };
                                var ext       = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));
                                var extension = ext.ToLower();
                                if (!AllowedFileExtensions.Contains(extension))
                                {
                                    var message = string.Format("Please Upload image of type .jpg,.gif,.png.");
                                    dict.Add("error", message);
                                    return(BadRequest("Please Upload image of type .jpg,.gif,.png.,.jpeg"));
                                }
                                else
                                {
                                    var filePath = HttpContext.Current.Server.MapPath("~/ProductImage/" + postedFile.FileName);
                                    postedFile.SaveAs(filePath);
                                    string imagepath = "/ProductImage/" + postedFile.FileName;
                                    int    image     = new ProductRepository().ImageUpload(pid, picimg, imagepath);
                                    if (image == 2)
                                    {
                                        return(NotFound());
                                    }
                                    if (image == 0)
                                    {
                                        return(BadRequest("Your image might be greater than the 1mb ,please upload a valid image"));
                                    }
                                }
                            }

                            var message1 = "/ProductImage/" + postedFile.FileName;
                            return(Ok(message1));
                        }
                        var res = string.Format("Please Upload a image.");
                        dict.Add("error", res);
                        return(NotFound());
                    }
                    catch (Exception ex)
                    {
                        var res = string.Format("please check your internet connection");
                        dict.Add("error", res);
                        return(NotFound());
                    }
                }
                else
                {
                    return(Unauthorized());
                }
            }
        }