public bool Update(User user) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { var userEntity = context.Users.SingleOrDefault(p => string.Equals(p.Email, user.Email, StringComparison.InvariantCultureIgnoreCase)); if (userEntity != null) { userEntity.FirstName = user.FirstName; userEntity.LastName = user.LastName; userEntity.DateOfBirth = user.DateOfBirth; userEntity.IsSubscribed = user.IsSubscribed; userEntity.Email = user.Email; if (!string.IsNullOrEmpty(user.Password)) { user.Password = _passwordEncryptionService.SetPassword(user.Password); } context.Entry(userEntity).State = EntityState.Modified; context.Users.Update(userEntity); context.SaveChanges(); return(true); } return(false); } }
public List <User> GetAllUsers() { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Users.ToList()); } }
/// <summary> /// If isUnitTest = true, this boots up the database without any products as it relies on file structure for images /// </summary> /// <param name="isUnitTest"></param> public void InitializeEFInMemoryDatabase(bool isUnitTest) { using (context = new ECommerceContextDb(GetOptions())) { LoadData(context, isUnitTest); } }
public Role GetRoleById(int roleId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Roles.Single(p => p.Id == roleId)); } }
public Category GetCategoryById(int categoryId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Categories.Single(p => p.Id == categoryId)); } }
public bool BrandHasProducts(int brandId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Products.Any(p => p.BrandId == brandId)); } }
/// <summary> /// Gets all Categories /// </summary> /// <returns></returns> public List <Category> GetSubMenuItems() { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Categories.ToList()); } }
public List <Brand> GetAllBrands() { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Brands.ToList()); } }
public bool RoleHasUsers(int roleId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Users.Any(p => p.RoleId == roleId)); } }
public bool IsEmailInUse(string emailAddress) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Users.Any(p => string.Equals(p.Email, emailAddress, StringComparison.InvariantCultureIgnoreCase))); } }
public bool CategoryHasProducts(int categoryId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Products.Any(p => p.CategoryId == categoryId)); } }
public List <ProductType> GetAllProductTypes() { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.ProductTypes.ToList()); } }
public Brand GetBrandById(int brandId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Brands.Single(p => p.Id == brandId)); } }
public ProductType GetProductTypeById(int productTypeId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.ProductTypes.Single(p => p.Id == productTypeId)); } }
public User GetUserById(int userId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Users.SingleOrDefault(p => p.Id == userId)); } }
/// <summary> /// Decreases the quantity of a Product by 1. /// </summary> /// <param name="productId"></param> /// <param name="sizeId"></param> /// <returns></returns> public bool ReduceProductQuantity(int productId, int sizeId, int quantityToReduce) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { var product = context.Products. Include("ProductType") .SingleOrDefault(p => p.Id == productId); if (product == null) { return(false); } var productSizes = context.ProductSizes.SingleOrDefault(p => p.ProductTypeId == product.ProductTypeId); var size = context.ProductSizes.SingleOrDefault(p => p.Id == sizeId); if (size == null) { return(false); } size.Quantity -= quantityToReduce; context.Entry(size).State = EntityState.Modified; context.SaveChanges(); return(true); } }
/// <summary> /// Gets the items for the Carousel on the Home page. /// </summary> /// <returns></returns> public List <Product> GetHomeCarouselItems() { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Products. Include("Images"). Where(p => p.Images.Any(c => c.FilePath.Contains("hero"))).ToList()); } }
public List <Transaction> GetDailyTakings(int numberOfDays) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Transactions .Where(p => p.CreatedDate > DateTime.Now.AddDays(-numberOfDays) && p.CreatedDate <= DateTime.Now) .Take(5).ToList()); } }
/// <summary> /// Creates a Transaction with the new Order /// </summary> /// <param name="newOrder"></param> /// <returns></returns> public Order PlaceOrder(Order newOrder) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { newOrder.Id = context.Orders.Add(newOrder).Entity.Id; newOrder.ReferenceNumber = Guid.NewGuid().ToString(); context.SaveChanges(); return(newOrder); } }
public bool Add(Category category) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { var categoryEntity = context.Categories.Add(category); context.Entry(category).State = EntityState.Added; context.SaveChanges(); return(context.Categories.Any(p => p.Id == categoryEntity.Entity.Id)); } }
public List <Transaction> GetLatestTransactions() { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { var startDate = DateTime.Now.AddDays(-8); var endDate = DateTime.Now.AddDays(-1); return(context.Transactions .Where(p => p.CreatedDate >= startDate && p.CreatedDate <= endDate).ToList()); } }
public bool Add(Role role) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { var roleEntity = context.Roles.Add(role); context.Entry(role).State = EntityState.Added; context.SaveChanges(); return(context.Brands.Any(p => p.Id == roleEntity.Entity.Id)); } }
/// <summary> /// Gets the Product based off of the Product ID provided. /// </summary> /// <param name="productId"></param> /// <returns></returns> public Product GetProductById(int productId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Products. Include("Images"). Include("Brand"). Include("Sizes"). Include("ProductType").Single(p => p.Id == productId)); } }
public bool Add(Brand brand) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { var brandEntity = context.Brands.Add(brand); context.Entry(brand).State = EntityState.Added; context.SaveChanges(); return(context.Brands.Any(p => p.Id == brandEntity.Entity.Id)); } }
public List <Product> GetAllProducts() { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(context.Products. Include("Images"). Include("Brand"). Include("Sizes"). Include("ProductType") .ToList()); } }
public List <User> GetLatestNewUsers(int numberOfUsers) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { var startDate = DateTime.Now.AddDays(-7); var endDate = DateTime.Now; return(context.Users .Where(p => p.CreatedDate >= startDate && p.CreatedDate <= endDate) .Take(numberOfUsers).ToList()); } }
public bool ProductNameExists(string productName, int?productId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { return(productId != null? context.Products .Any(p => string.Equals(p.ProductName, productName, StringComparison.InvariantCultureIgnoreCase) && p.Id != productId.Value) : context.Products .Any(p => string.Equals(p.ProductName, productName, StringComparison.InvariantCultureIgnoreCase))); } }
public bool BrandNameExists(Brand brand) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { if (brand.Id != 0) { return(context.Brands.Any(p => string.Equals(brand.BrandName, p.BrandName, StringComparison.InvariantCultureIgnoreCase) && p.Id != brand.Id)); } return(context.Brands.Any(p => string.Equals(brand.BrandName, p.BrandName, StringComparison.InvariantCultureIgnoreCase))); } }
/// <summary> /// Gets a list of products selected at random with the maximum amount being provided in the parameter. /// </summary> /// <param name="numberOfProducts"></param> /// <returns></returns> public List <Product> GetRandomProducts(int numberOfProducts) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { var listAllProducts = context.Products. Include("Images"). Include("Brand"). Include("Sizes"). Include("ProductType").ToList(); return(listAllProducts.Take(3).ToList()); } }
/// <summary> /// Gets a list of products that the User has previously viewed or purchased. /// </summary> /// <param name="numberOfProducts"></param> /// <returns></returns> public List <Product> GetSuggestedProductsByUser(int userId) { using (var context = new ECommerceContextDb(new ECommerceDatabase.StartupDatabase().GetOptions())) { var listAllProducts = context.Products. Include("Images"). Include("Brand"). Include("Sizes"). Include("ProductType").ToList(); return(listAllProducts.Take(3).ToList()); } }