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); } } }
public IHttpActionResult UpdateCart(int cid, CartModel model, string token) { try { using (ShoppingELFEntities context = new ShoppingELFEntities()) { UserTable user = new UserTable(); string username = TokenManager.ValidateToken(token); user = context.UserTable.FirstOrDefault(m => m.email == username); if (user != null && user.Role == "User") { bool x = new UserRepository().UpdateCartModel(cid, model); if (x) { return(Ok("updated cart")); } else { return(Ok("Something went wrong , please try again later")); } } else { return(Unauthorized()); } } } catch (Exception ex) { return(BadRequest()); } }
public IHttpActionResult GetCart(string token) { try { using (ShoppingELFEntities context = new ShoppingELFEntities()) { UserTable user = new UserTable(); string username = TokenManager.ValidateToken(token); user = context.UserTable.FirstOrDefault(m => m.email == username); if (user != null && user.Role == "User") { var x = new UserRepository().GetCart(user.UserID); return(Ok(x)); } else { return(Unauthorized()); } } } catch (Exception ex) { return(BadRequest()); } }
public IHttpActionResult EditAddress(AddressModel model, string token) { try { using (ShoppingELFEntities context = new ShoppingELFEntities()) { UserTable user = new UserTable(); string username = TokenManager.ValidateToken(token); user = context.UserTable.FirstOrDefault(m => m.email == username); if (user != null && user.Role == "User") { bool x = new UserModel().EditAddress(user.UserID, model); if (x) { return(Ok("Address updated successfully")); } else { return(Ok("Something went Wrong , unable to update Address")); } } else { return(Unauthorized()); } } } catch (Exception ex) { return(BadRequest()); } }
public IHttpActionResult EditAccount(UserModel model, string token) { try { using (ShoppingELFEntities context = new ShoppingELFEntities()) { UserTable user = new UserTable(); string username = TokenManager.ValidateToken(token); user = context.UserTable.FirstOrDefault(m => m.email == username); if (user != null && user.Role == "User") { bool x = new UserModel().EditAccount(user.UserID, model); if (x) { return(Ok("Account details has been updated")); } else { return(Ok("unable to update account")); } } else { return(Unauthorized()); } } } catch (Exception ex) { return(BadRequest()); } }
public List <CartModel> GetCart(int uid) { using (var context = new ShoppingELFEntities()) { var result = context.CartTable .Where(x => x.UserID == uid) .Select(x => new CartModel() { UserID = uid, PID = x.PID, CartID = x.CartID, Quantity = x.Quantity, SizeModel = new SizeModel() { productPrice = x.SizeTable.productPrice, productSize = x.SizeTable.productSize, ProductModel = new ProductModel() { productName = x.SizeTable.ProductTable.productName, productBrand = x.SizeTable.ProductTable.productBrand, productDetails = x.SizeTable.ProductTable.productDetails, picture1 = x.SizeTable.ProductTable.picture1, picture2 = x.SizeTable.ProductTable.picture2, picture3 = x.SizeTable.ProductTable.picture3, picture4 = x.SizeTable.ProductTable.picture4 } } }).ToList(); return(result); } }
public IHttpActionResult OrderNow(int pid, OrderModel model, string token) { try { using (ShoppingELFEntities context = new ShoppingELFEntities()) { UserTable user = new UserTable(); string username = TokenManager.ValidateToken(token); user = context.UserTable.FirstOrDefault(m => m.email == username); if (user != null && user.Role == "User") { int x = new UserRepository().OrderNow(user.UserID, pid, model); if (x == 1) { new UserRepository().ClearCart(user.UserID); return(Ok("Order Placed Successfully")); } else { return(Ok("The item you are looking for seems to be out of stock")); } } else { return(Unauthorized()); } } } catch (Exception ex) { return(BadRequest()); } }
public List <SizeModel> ShowSellerProductSize(int pid) { using (ShoppingELFEntities context = new ShoppingELFEntities()) { var result = context.SizeTable .Where(x => x.ProductID == pid) .Select(x => new SizeModel() { PID = x.PID, ProductID = x.ProductID, productSize = x.productSize, productQuantity = x.productQuantity, productPrice = x.productPrice, ProductModel = new ProductModel() { productName = x.ProductTable.productName, picture1 = x.ProductTable.picture1, picture2 = x.ProductTable.picture2, picture3 = x.ProductTable.picture3, picture4 = x.ProductTable.picture4, productBrand = x.ProductTable.productBrand, productDetails = x.ProductTable.productDetails, ProductID = x.ProductTable.ProductID } }).ToList(); return(result); } }
public IHttpActionResult DeleteFromCart(int cid, string token) { try { using (ShoppingELFEntities context = new ShoppingELFEntities()) { UserTable user = new UserTable(); string username = TokenManager.ValidateToken(token); user = context.UserTable.FirstOrDefault(m => m.email == username); if (user != null && user.Role == "User") { int x = new UserRepository().RemoveFromCart(cid); if (x == 1) { return(Ok("Item removed from cart successfully")); } else { return(BadRequest("Cart is already empty")); } } else { return(Unauthorized()); } } } catch (Exception ex) { return(BadRequest()); } }
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)); } }
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 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()); } }
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()); } }
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()); } }
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()); } }
public IHttpActionResult AddToCart(int pid, string token) { try { using (ShoppingELFEntities context = new ShoppingELFEntities()) { UserTable user = new UserTable(); string username = TokenManager.ValidateToken(token); user = context.UserTable.FirstOrDefault(m => m.email == username); if (user != null && user.Role == "User") { var v = context.CartTable.Where(a => a.PID == pid).FirstOrDefault(); if (v != null) { return(BadRequest("Product already added in the cart")); } else { var x = new UserRepository().AddToCart(user.UserID, pid); return(Ok("Product has been added to cart Successfully")); } } else { return(Unauthorized()); } } } catch (Exception ex) { return(BadRequest()); } }
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()); } }
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()); } }
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 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)); } }
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); } }
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)); } }
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)); } }
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); } } }
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 bool IsEmailExist(string Email) { using (ShoppingELFEntities se = new ShoppingELFEntities()) { var v = se.UserTable.Where(a => a.email == Email).FirstOrDefault(); return(v != null); } }
public string Password(string Email) { ShoppingELFEntities context = new ShoppingELFEntities(); UserTable us = new UserTable(); us = context.UserTable.SingleOrDefault(x => x.email == Email); string pass = Convert.ToString(us.password); return(pass); }
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); }
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 JWTAuthenticationIdentity(string userName) // : base(userName) //{ // email = userName; //} public bool verification(string Email) { //UserModel model = new UserModel(); ShoppingELFEntities context = new ShoppingELFEntities(); UserTable Fac = new UserTable(); ////FacultyTable faculty1 = new FacultyTable(); Fac = context.UserTable.SingleOrDefault(m => m.email == Email); var y = Convert.ToBoolean(Fac.IsEmailVerified); return(y); }