public static string name() { string data; string email = HttpContext.Current.User.Identity.Name; try { using (var db = new dekkOnlineEntities()) { var iduser = db.AspNetUsers.Where(s => s.UserName == email).FirstOrDefault(); if (iduser != null) { var userdata = db.UserAddress.Where(s => s.IdUser == iduser.Id).FirstOrDefault(); if (userdata != null) { data = userdata.FirstName + " " + userdata.LastName; } else { data = iduser.UserName; } return(data); } else { data = "User"; return(data); } } } catch (Exception ex) { throw; } }
public string userId(string email) { string result = ""; try { using (var db = new dekkOnlineEntities()) { var user = db.AspNetUsers.Where(s => s.Email == email).Select(s => s.Id).FirstOrDefault(); if (user != null) { result = user; } else { result = ""; } } } catch (Exception) { throw; } return(result); }
public bool ValidateUserEmail(string email1, string iduser) { bool result = false; try { using (dekkOnlineEntities db = new dekkOnlineEntities()) { var emailuser = db.AspNetUsers.Where(s => s.Id == iduser).Select(s => s.Email).FirstOrDefault().ToString(); var emailnew = db.AspNetUsers.Where(s => s.Email == email1).Select(s => s.Email).FirstOrDefault().ToString(); if (emailnew != null && emailuser != emailnew) { result = true; } else if (emailnew == null || emailuser == emailnew) { result = false; } return(result); } } catch (Exception ex) { throw; } }
//LOAD SYZES PER DEKK DE-5 TASK 1 TASK 2 public List<ResultProduct> SizesperDekk(string dekk) { List<ResultProduct> result = null; try { using (var db = new dekkOnlineEntities()) { result = (from x in db.products where (x.proName == dekk && x.proInventory > 0) select new ResultProduct { Id = x.proId, Profile = x.proDimensionProfile, Width = x.proDimensionWidth, Diameter = x.proDimensionDiameter, Stock = x.proInventory }).ToList(); } } catch (Exception ex) { return result; } return result; }
//Load Categories public List<ResultCategories> loadCategories() { List<ResultCategories> Categories = null; try { using (var db = new dekkOnlineEntities()) { Categories = (from cat in db.categories //where (cat.products.Count > 0) orderby cat.catName select new ResultCategories { catId = cat.catId, catName = cat.catName, catDescription = cat.catDescription, catStatus = cat.catStatus, catImage = cat.catImage }).ToList(); } } catch (Exception ex) { throw; } return Categories; }
public bool UpdatePromo(string code, string idusercookie) { bool result = false; try { using (var db = new dekkOnlineEntities()) { var registro = db.PromoCodeUsed.Where(s => s.idUser == idusercookie && s.Used == false).FirstOrDefault(); if (registro != null) { registro.PromoCode = code; db.Entry(registro).State = EntityState.Modified; db.SaveChanges(); result = true; } else { result = false; } return(result); } } catch (Exception ex) { throw; } }
public bool updateDeleveryType(string IdUser1, string idUserCookies) { bool result = false; try { using (var db = new dekkOnlineEntities()) { var registro = db.DeliveryType.Where(s => s.IdUser == idUserCookies).OrderByDescending(s => s.IdUser).FirstOrDefault(); if (registro != null) { registro.IdUser = IdUser1; db.Entry(registro).State = EntityState.Modified; db.SaveChanges(); result = true; } else { result = false; } } } catch (Exception) { } return(result); }
public bool ValidateUserworkshop(string id) { bool result = false; try { using (var db = new dekkOnlineEntities()) { var user = db.WorkshopUser.Where(s => s.idUser == id).FirstOrDefault(); if (user != null) { result = true; } else { result = false; } } } catch (Exception ex) { result = false; return(result); throw; } return(result); }
public bool UpdateRoleUser(string email) { bool result = false; try { using (dekkOnlineEntities db = new dekkOnlineEntities()) { var useremail = db.AspNetUsers.Where(s => s.Email == email).FirstOrDefault(); if (useremail != null) { useremail.Roles = 1; useremail.Active = true; db.Entry(useremail).State = EntityState.Modified; db.SaveChanges(); result = true; } else { result = false; } return(result); } } catch (Exception ex) { throw; } }
public bool existingMail(string email) { bool result = false; try { using (var db = new dekkOnlineEntities()) { var user = db.AspNetUsers.Where(s => s.Email == email).FirstOrDefault(); if (user != null) { result = true; } else { result = false; } } } catch (Exception) { result = false; } return(result); }
////DE-23 1 //public List<ResultDataUser> dataUser(string idUser) //{ // List<ResultDataUser> user = null; // try // { // using (var db = new dekkOnlineEntities()) // { // user = (from us in db.UserAddress // join aspuser in db.AspNetUsers on us.IdUser equals aspuser.Id // where us.IdUser == idUser // select new ResultDataUser // { // IdUser = us.IdUser, // FirstName = us.FirstName, // LastName = us.LastName, // Address = us.Address, // Phone = us.Phone, // ZipCode = us.ZipCode.ToString(), // Latitude = us.Latitude, // length = us.Length, // Image = us.Image, // Email = aspuser.Email // }).ToList(); // } // } // catch (Exception) // { // throw; // } // return user; //} public bool validaLogin(string user, string pass) { bool valUser = false; try { using (var db = new dekkOnlineEntities()) { var result = db.AspNetUsers.Where(s => s.UserName == user && s.PasswordHash == pass).FirstOrDefault(); if (result != null) { valUser = true; } else { valUser = false; } } } catch (Exception ex) { } return(valUser); }
//DELETE FROM CART DE-11 TASK 5 public bool DeleteProductFromCart(string idcart, string idUser) { Framework.encryptdecrypt en = new encryptdecrypt(); try { int id = Convert.ToInt32(en.DesEncriptar(idcart)); using (var db = new dekkOnlineEntities()) { var addCart = new ShoppingCart(); var d = db.ShoppingCart.Where(x => x.Id == id).FirstOrDefault(); if (d != null) { var promocodeused = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.Used == false).FirstOrDefault(); if (promocodeused != null) { var percent = db.PromotionCode.Where(s => s.IdCode == promocodeused.PromoCode).Select(s => s.PercentCode).FirstOrDefault(); percent = percent / 100; promocodeused.TotalPrice = promocodeused.TotalPrice - d.Price; promocodeused.TotalPriceFinal = promocodeused.TotalPrice - (percent * (promocodeused.TotalPrice)); db.Entry(promocodeused).State = EntityState.Modified; } db.ShoppingCart.Remove(d); db.SaveChanges(); var user = db.ShoppingCart.Where(s => s.IdUser == idUser && s.Status == false).FirstOrDefault(); if (user != null) { return(true); } else if (user == null) { var promocodeused2 = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.Used == false).FirstOrDefault(); if (promocodeused2 != null) { db.PromoCodeUsed.Remove(promocodeused2); db.SaveChanges(); return(true); } else { return(true); } } return(true); } else { return(false); } } } catch (Exception ex) { //_Error = ex; return(false); } }
public List <ResulUserWorkShop> infoStep2(string User) { List <ResulUserWorkShop> result = null; List <ResultWorkshop> listWorkshop = null; try { using (var db = new dekkOnlineEntities()) { var userAddress = db.UserAddress.Where(s => s.IdUser == User).FirstOrDefault(); string userEmail = db.AspNetUsers.Where(s => s.Id == User).Select(s => s.UserName).FirstOrDefault(); Workshop workshop = new Workshop(); if (userAddress == null) { listWorkshop = workshop.loadWorkshopAddress(0); result = new List <ResulUserWorkShop> { new ResulUserWorkShop { workshop = listWorkshop, zipcode = 0, firstName = "", lastName = "", address = "", email = "", mobile = "" } }; } else { listWorkshop = workshop.loadWorkshopAddress((int)userAddress.ZipCode); result = new List <ResulUserWorkShop> { new ResulUserWorkShop { workshop = listWorkshop, zipcode = (int)userAddress.ZipCode, firstName = userAddress.FirstName, lastName = userAddress.LastName, address = userAddress.Address, email = userEmail, mobile = userAddress.Phone } }; } } } catch (Exception ex) { throw; } return(result); }
public bool UpdateDataUser(string zipcore, string name, string lastname, string address, string email, string mobile, string idUser1) { bool result = false; try { using (dekkOnlineEntities db = new dekkOnlineEntities()) { var userdata = db.UserAddress.Where(s => s.IdUser == idUser1).FirstOrDefault(); var useremail = db.AspNetUsers.Where(s => s.Id == idUser1).FirstOrDefault(); if (userdata == null && useremail != null) { UserAddress us = new UserAddress(); us.IdUser = idUser1; us.FirstName = name; us.LastName = lastname; us.Address = address; us.Phone = mobile; us.ZipCode = Convert.ToInt32(zipcore); //us.WorkShopManager = false; //useremail.Email = email; //useremail.UserName = email; //db.Entry(useremail).State = EntityState.Modified; db.UserAddress.Add(us); db.SaveChanges(); result = true; } else if (userdata != null && useremail != null) { userdata.FirstName = name; userdata.LastName = lastname; userdata.Address = address; userdata.Phone = mobile; userdata.ZipCode = Convert.ToInt32(zipcore); //userdata.WorkShopManager = false; //useremail.Email = email; //useremail.UserName = email; db.Entry(userdata).State = EntityState.Modified; //db.Entry(useremail).State = EntityState.Modified; db.SaveChanges(); result = true; } else { result = false; } return(result); } } catch (Exception ex) { throw; } }
//DE-2 2 public List<ResultProduct> loadProducts(int? catId, int? width, int? profile, int? diameter, Guid? braId) { List<ResultProduct> result = null; try { using (var db = new dekkOnlineEntities()) { result = (from pro in db.products where (pro.proStatus == true //&& pro.categoriesDP.cdpStatus == true && (catId == null || pro.catId == catId) && (width == null || pro.proDimensionWidth == width) && (profile == null || pro.proDimensionProfile == profile) && (diameter == null || pro.proDimensionDiameter == diameter) && (braId.HasValue == false || pro.braId == braId)) && (!pro.proNameDP.ToUpper().Contains("TEST")) && (!pro.proNameDP.ToUpper().Contains("TESET")) //&& pro.catId != null //&& (!pro.proNameDP.Contains("Test")) select new ResultProduct { Id = pro.proId, Image = pro.proImage, CatId = pro.categories.catId, CategoryImage = pro.categories.catImage, CategoryName = pro.categories.catName, Brand = pro.brands.braName, BrandImage = pro.brands.braImage, Name = pro.proName, Width = pro.proDimensionWidth, Profile = pro.proDimensionProfile, Diameter = pro.proDimensionDiameter, TyreSize = pro.proTyreSize, Fuel = pro.proFuel, Wet = pro.proWet, Noise = pro.proNoise, //Price = pro.proSuggestedPrice, Price = pro.proSuggestedPrice != null ? (int)Math.Floor((decimal)pro.proSuggestedPrice) : 0, Stock = pro.proInventory, SpeedIndex = pro.proSpeed, LoadIndex = pro.proLoadIndex }).ToList(); } } catch (Exception ex) { throw; } return result; }
//DE-14 2 public bool updateAddressUser(string idUser, string firstName, string lastName, string address, string phone, int zipCode, string latitude, string length) { bool Result = false; try { using (var db = new dekkOnlineEntities()) { var result = db.UserAddress.Where(s => s.IdUser == idUser).FirstOrDefault(); if (result != null) { result.FirstName = firstName; result.LastName = lastName; result.Address = address; result.Phone = phone; result.ZipCode = zipCode; result.Latitude = latitude; result.Length = length; //result.WorkShopManager = false; db.Entry(result).State = EntityState.Modified; db.SaveChanges(); Result = true; } else if (result == null) { UserAddress us = new UserAddress(); us.FirstName = firstName; us.LastName = lastName; us.Address = address; us.Phone = phone; us.ZipCode = zipCode; us.Latitude = latitude; us.Length = length; db.UserAddress.Add(us); db.SaveChanges(); Result = true; } else { Result = false; } } } catch (Exception ex) { throw; } return(Result); }
public string User(string user) { try { using (var db = new dekkOnlineEntities()) { var idUser = db.AspNetUsers.Where(s => s.Email == user).Select(s => s.Id).FirstOrDefault(); return(idUser); } } catch (Exception ex) { throw; } }
//LOAD CURRENT POINTS PER USER DE-11 TASK 3 public int LoadPointsPerUser(string idUser) { var NowPointsLoad = (dynamic)null; try { using (var db = new dekkOnlineEntities()) { var user = db.AspNetUsers.Where(s => s.Id == idUser).FirstOrDefault(); if (user != null) { NowPointsLoad = db.DetailUserPoints.Where(s => s.IdUser == idUser && s.StatusofPromo == true).Select(s => s.PointsEarned).Sum().ToString(); if (NowPointsLoad == null || NowPointsLoad == "") { NowPointsLoad = "0"; } var UserPoints = db.UserPoints.Where(s => s.IdUser == idUser).FirstOrDefault(); if (UserPoints == null) { var points = new Entity.UserPoints(); points.IdUser = idUser; points.Points = Convert.ToInt32(NowPointsLoad); db.UserPoints.Add(points); db.SaveChanges(); return(Convert.ToInt32(NowPointsLoad)); } else { UserPoints.Points = Convert.ToInt32(NowPointsLoad); db.Entry(UserPoints).State = EntityState.Modified; db.SaveChanges(); return(Convert.ToInt32(NowPointsLoad)); } } else { return(0); } } } catch (Exception ex) { throw; } }
//DE-14 5 public bool addToUserAddress(string idUser, string firstName, string lastName, string address, string phone, int zipCode, string latitude, string length) { bool result = false; try { using (var db = new dekkOnlineEntities()) { var user = db.UserAddress.Where(s => s.IdUser == idUser).FirstOrDefault(); if (user == null) { var addUserAddress = new Entity.UserAddress(); addUserAddress.IdUser = idUser; addUserAddress.FirstName = firstName; addUserAddress.LastName = lastName; addUserAddress.Address = address; addUserAddress.Phone = phone; addUserAddress.ZipCode = zipCode; addUserAddress.Latitude = latitude; addUserAddress.Length = length; //addUserAddress.WorkShopManager = false; db.UserAddress.Add(addUserAddress); db.SaveChanges(); result = true; } else { user.FirstName = firstName; user.LastName = lastName; user.Address = address; user.Phone = phone; user.ZipCode = zipCode; user.Latitude = latitude; user.Length = length; //user.WorkShopManager = false; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); result = true; } } } catch (Exception ex) { result = false; } return(result); }
public string IdUser(string email) { var user = (dynamic)null; try { using (var db = new dekkOnlineEntities()) { user = db.AspNetUsers.Where(s => s.UserName == email).Select(s => s.Id).FirstOrDefault().ToString(); } } catch (Exception ex) { throw; } return(user); }
//DE-14 1 public string loadAddressUser(string idUser) { var UserAddress = (dynamic)null; try { using (var db = new dekkOnlineEntities()) { UserAddress = (from user in db.UserAddress where user.IdUser == idUser select new { adreess = user.Address, latitude = user.Latitude, length = user.Length }).FirstOrDefault().ToString(); } } catch (Exception ex) { throw; } return(UserAddress); }
//ADD TO CART DE-5 TASK 3 public bool AddToCart(string idUser, int id_dekk, int id_quantity) { try { using (var db = new dekkOnlineEntities()) { var productPrice = db.products.Where(s => s.proId == id_dekk).Select(x => x.proSuggestedPrice).FirstOrDefault(); decimal price = Convert.ToDecimal(productPrice) * id_quantity; var promocodeused = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.Used == false).FirstOrDefault(); Entity.ShoppingCart productShoppingCart = db.ShoppingCart.Where(s => s.proId == id_dekk && s.IdUser.Equals(idUser) && s.Status == false).FirstOrDefault(); price = (int)Math.Floor(price); if (productShoppingCart == null) { Entity.ShoppingCart addCart = new Entity.ShoppingCart(); addCart.IdUser = idUser; addCart.proId = id_dekk; addCart.quantity = id_quantity; addCart.Price = price; addCart.Status = false; db.ShoppingCart.Add(addCart); } else { productShoppingCart.quantity = id_quantity; productShoppingCart.Price = price; } if (promocodeused != null) { var percent = db.PromotionCode.Where(s => s.IdCode == promocodeused.PromoCode).Select(s => s.PercentCode).FirstOrDefault(); percent = percent / 100; promocodeused.TotalPrice = promocodeused.TotalPrice + price; promocodeused.TotalPriceFinal = promocodeused.TotalPrice - (percent * (promocodeused.TotalPrice)); db.Entry(promocodeused).State = EntityState.Modified; } db.SaveChanges(); return(true); } } catch (Exception ex) { //_Error = ex; return(false); } }
//DE-23 1 public List <ResultDataUser> dataUser(string idUser) { List <ResultDataUser> user = null; try { using (var db = new dekkOnlineEntities()) { user = (from us in db.UserAddress join aspuser in db.AspNetUsers on us.IdUser equals aspuser.Id where us.IdUser == idUser select new ResultDataUser { IdUser = us.IdUser, FirstName = us.FirstName, LastName = us.LastName, Address = us.Address, Phone = us.Phone, ZipCode = us.ZipCode.ToString(), Latitude = us.Latitude, length = us.Length, Image = us.Image, Email = aspuser.Email }).ToList(); if (user.Count == 0) { user = (from us in db.AspNetUsers where us.Id == idUser select new ResultDataUser { Email = us.Email }).ToList(); } } } catch (Exception) { throw; } return(user); }
public bool emailPromo(string idUser, string correos, string mensaje) { bool result = false; var mail = new Mail(); try { using (var db = new dekkOnlineEntities()) { var emailUser = db.AspNetUsers.Where(s => s.Id == idUser).Select(s => s.Email).FirstOrDefault(); mail.sendEmailPromo(emailUser, correos, mensaje); result = true; } } catch (Exception ex) { result = false; } return(result); }
public bool SavePromoCode(string promo, string email) { bool result = false; try { using (dekkOnlineEntities db = new dekkOnlineEntities()) { var useremail = db.AspNetUsers.Where(s => s.Email == email).FirstOrDefault(); var promocodeuser = db.PromotionCode.Where(s => s.IdCode == promo).FirstOrDefault(); if (promocodeuser == null) { DateTime date1 = DateTime.Now; DateTime date2 = date1.AddYears(50); PromotionCode promous = new PromotionCode(); promous.IdCode = promo; promous.IdUser = useremail.Id; promous.PercentCode = 10; promous.DateStart = date1; promous.DateEnd = date2; promous.Points = 10; promous.DescriptionCode = "PromoCode for Costumer"; db.PromotionCode.Add(promous); db.SaveChanges(); result = true; } else { result = false; } return(result); } } catch (Exception ex) { throw; } }
//DE-2 1 public List<ResultCategories> loadType() { List<ResultCategories> result = null; try { using (var db = new dekkOnlineEntities()) { result = (from cat in db.categories where (cat.catStatus == true) select new ResultCategories { catId = cat.catId, catName = cat.catName.ToUpper() }).ToList(); } } catch (Exception ex) { throw; } return result; }
//DE-2 1 public List<ResultSize> loadDimensionProfile() { List<ResultSize> result = null; try { using (var db = new dekkOnlineEntities()) { result = (from pro in db.products where (pro.proDimensionProfile.HasValue) && pro.proInventory != 0 select new ResultSize { Id = pro.proDimensionProfile.Value.ToString(), Size = pro.proDimensionProfile.Value.ToString() }).Distinct().OrderBy(c => c.Id).ToList(); } } catch (Exception ex) { throw; } return result; }
public bool UndoPromoCode(string idUser) { try { using (var db = new dekkOnlineEntities()) { var a = db.PromoCodeUsed.Where(s => s.idUser == idUser && s.Used == false).OrderByDescending(s => s.id).FirstOrDefault(); if (a != null) { db.PromoCodeUsed.Remove(a); db.SaveChanges(); return(true); } else { return(false); } } } catch (Exception ex) { return(false); } }
public string UpdateUserImage(string path, string idUser1) { try { using (var db = new dekkOnlineEntities()) { var UserInfo = db.UserAddress.Where(s => s.IdUser == idUser1).FirstOrDefault(); if (UserInfo != null) { UserInfo.Image = path; db.Entry(UserInfo).State = EntityState.Modified; db.SaveChanges(); var image = db.UserAddress.Where(s => s.IdUser == idUser1).Select(s => s.Image).FirstOrDefault(); return(image); } else if (UserInfo == null) { UserAddress us2 = new UserAddress(); us2.IdUser = idUser1; us2.Image = path; db.UserAddress.Add(us2); db.SaveChanges(); var image = db.UserAddress.Where(s => s.IdUser == idUser1).Select(s => s.Image).FirstOrDefault(); return(image); } else { return(null); } } } catch (Exception ex) { return(null); } }
//DE-2 1 public List<ResultBrands> loadBrands() { List<ResultBrands> result = null; try { using (var db = new dekkOnlineEntities()) { result = (from bra in db.brands where (bra.products.Count > 0) orderby bra.braName select new ResultBrands { braId = bra.braId, braName = bra.braName }).ToList(); } } catch (Exception ex) { throw; } return result; }