public List <Order> SearchOrders(string userEmail, int?orderID, int?orderStatus, int?pageNo, int pageSize) { eCommerceContext context = new eCommerceContext(); var orders = context.Orders.AsQueryable(); if (orderID.HasValue && orderID.Value > 0) { orders = orders.Where(x => x.ID == orderID.Value); } if (!string.IsNullOrEmpty(userEmail)) { orders = orders.Where(x => x.CustomerEmail.Equals(userEmail)); } if (orderStatus.HasValue && orderStatus.Value > 0) { orders = orders.Where(x => x.OrderHistory.OrderByDescending(y => y.ModifiedOn).FirstOrDefault().OrderStatus == orderStatus); } pageNo = pageNo ?? 1; var skipCount = (pageNo.Value - 1) * pageSize; return(orders.OrderByDescending(x => x.PlacedOn).Skip(skipCount).Take(pageSize).ToList()); }
public int GetProductCount(List <int> categoryIDs, string searchTerm, decimal?from, decimal?to) { eCommerceContext context = new eCommerceContext(); var Products = context.Products.AsQueryable(); if (categoryIDs != null && categoryIDs.Count > 0) { Products = Products.Where(x => categoryIDs.Contains(x.CategoryID)); } if (!string.IsNullOrEmpty(searchTerm)) { Products = Products.Where(x => x.Name.ToLower().Contains(searchTerm.ToLower())); } if (from.HasValue && from.Value > 0.0M) { Products = Products.Where(x => x.Price >= from.Value); } if (to.HasValue && to.Value > 0.0M) { Products = Products.Where(x => x.Price <= to.Value); } return(Products.Count()); }
public async Task <List <Category> > SearchCategory(string Name) { if (Name == null) { return(null); } eCommerceContext context = new eCommerceContext(); List <Category> res = await context.Categories.Include(x => x.ParentCategory) .Include(a => a.Products.Select(f => f.ProductPictures.Select(t => t.Picture))) .Where(x => x.Name == Name || Name == x.ArName).ToListAsync(); // int i = 0; for (int i = 0; i < res.Count(); i++) { res[i].Description = Method.RemoveRegx(res[i].Description); foreach (var item in res[i].Products) { item.Description = Method.RemoveRegx(item.Description); item.ArDescription = Method.RemoveRegx(item.ArDescription); } } return(res); }
public Category GetCategoryByID(int ID) { using (var context = new eCommerceContext()) { return(context.Categories.Find(ID)); } }
public List <Comment> GetComments(string userID, string searchTerm, int entityID, int?pageNo, int recordsSize) { eCommerceContext context = new eCommerceContext(); pageNo = pageNo ?? 1; var skipCount = (pageNo.Value - 1) * recordsSize; var comments = context.Comments.Where(x => x.EntityID == entityID) .AsQueryable(); if (!string.IsNullOrEmpty(userID)) { comments = comments.Where(x => x.UserID == userID); } if (!string.IsNullOrEmpty(searchTerm)) { comments = comments.Where(x => x.Text.ToLower().Contains(searchTerm.ToLower())); } return(comments.OrderByDescending(x => x.TimeStamp) .Skip(skipCount) .Take(recordsSize) .ToList()); }
public Supplier GetSupplierByID(int ID) { using (var context = new eCommerceContext()) { return(context.Suppliers.Find(ID)); } }
public async Task <JsonResult> UpdateProfile(eCommerceUser model) { JsonResult jResult = new JsonResult(); eCommerceContext context = new eCommerceContext(); if (model != null) { var UserManager = new UserManager <eCommerceUser>(new UserStore <eCommerceUser>(context)); var user = await UserManager.FindByIdAsync(model.Id); if (user != null) { user.FullName = model.FullName; user.Email = model.Email; user.UserName = model.UserName; user.PhoneNumber = model.PhoneNumber; user.Country = model.Country; user.City = model.City; user.Address = model.Address; user.ZipCode = model.ZipCode; var result = await UserManager.UpdateAsync(user); jResult.Data = new { Success = result.Succeeded, Message = string.Join("\n", result.Errors) }; return(jResult); } } else { jResult.Data = new { Success = false, Message = "Invalid User" }; } return(jResult); }
public async Task <JsonResult> ResetPassword(ResetPasswordVM ResetVM) { eCommerceContext context = new eCommerceContext(); var UserManager = new UserManager <eCommerceUser>(new UserStore <eCommerceUser>(context)); JsonResult jResult = new JsonResult(); eCommerceUser user = await userApiService.GetUserById(ResetVM.UserId); if (user != null) { var result = await UserManager.ChangePasswordAsync(ResetVM.UserId, ResetVM.OldPassword, ResetVM.NewPassword); if (result.Succeeded) { await userApiService.Save(); jResult.Data = new { Success = true, Messages = "Your password has been reset. Please login with your updated credentials now." }; return(jResult); } else { jResult.Data = new { Success = false, Messages = "Unable to reset password." }; } } return(jResult); }
public void UpdateConfiguration(Configuration configuration) { eCommerceContext context = new eCommerceContext(); context.Entry(configuration).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
public void UpdateCategory(Category category) { eCommerceContext context = new eCommerceContext(); context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
public bool SaveOrder(Order order) { eCommerceContext context = new eCommerceContext(); context.Orders.Add(order); return(context.SaveChanges() > 0); }
public void UpdateSupplier(Supplier supplier) { eCommerceContext context = new eCommerceContext(); context.Entry(supplier).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
public void SaveSupplier(Supplier supplier) { eCommerceContext context = new eCommerceContext(); context.Suppliers.Add(supplier); context.SaveChanges(); }
public async Task <Order> GetOrderById(int Id) { eCommerceContext context = new eCommerceContext(); return(await context.Orders.Include(x => x.Promo).Include(x => x.OrderItems.Select(a => a.Product)) .Include(x => x.OrderHistory).Include(x => x.OrderItems.Select(f => f.Product.ProductPictures.Select(a => a.Picture))) .FirstOrDefaultAsync(x => x.ID == Id)); }
public List <Product> SearchFeaturedProducts(int pageSize, List <int> excludeProductIDs = null) { excludeProductIDs = excludeProductIDs ?? new List <int>(); eCommerceContext context = new eCommerceContext(); return(context.Products.Where(a => a.isFeatured && !excludeProductIDs.Contains(a.ID)).OrderByDescending(x => x.ID).Take(pageSize).ToList()); }
public void SaveProduct(Product Product) { eCommerceContext context = new eCommerceContext(); context.Products.Add(Product); context.SaveChanges(); }
public List <Product> GetDataEntryProducts(string sentUserId) { eCommerceContext context = new eCommerceContext(); var Products = context.Products.Where(x => x.UserId == sentUserId).ToList(); return(Products); }
public List <CountryCode> GetCountryCodes() { eCommerceContext context = new eCommerceContext(); var codes = context.CountryCodes.ToList(); return(codes); }
public bool AddComment(Comment comment) { eCommerceContext context = new eCommerceContext(); context.Comments.Add(comment); return(context.SaveChanges() > 0); }
public void SaveCategory(Category category) { eCommerceContext context = new eCommerceContext(); context.Categories.Add(category); context.SaveChanges(); }
public eCommerceUser GetUserById(string Id) { eCommerceContext context = new eCommerceContext(); var user = context.Users.Find(Id); return(user); }
public eCommerceUser GetUserByUsername(string Username) { eCommerceContext context = new eCommerceContext(); var user = context.Users.Find(Username); return(user); }
public bool AddOrderHistory(OrderHistory orderHistory) { eCommerceContext context = new eCommerceContext(); context.OrderHistories.Add(orderHistory); return(context.SaveChanges() > 0); }
public void SavePromo(Promo Promo) { eCommerceContext context = new eCommerceContext(); context.Promos.Add(Promo); context.SaveChanges(); }
public async Task <List <Category> > GetAllCategrise() { eCommerceContext context = new eCommerceContext(); return(await context.Categories .Include(x => x.ParentCategory) .Include(a => a.Products.Select(f => f.ProductPictures.Select(t => t.Picture))). ToListAsync()); }
public int SavePicture(Picture picture) { eCommerceContext context = new eCommerceContext(); context.Pictures.Add(picture); context.SaveChanges(); return(picture.ID); }
public async Task <List <Comment> > GetUserComments(string userId) { if (userId == null || userId.IsEmpty()) { return(null); } eCommerceContext context = new eCommerceContext(); return(await context.Comments.Include(x => x.User).Where(x => x.UserID == userId).ToListAsync()); }
public Payment AddUserPayment(Payment payment) { eCommerceContext context = new eCommerceContext(); var paymentToAdd = context.Payment.Add(payment); context.SaveChanges(); return(paymentToAdd); }
public void UpdatePromo(Promo Promo) { eCommerceContext context = new eCommerceContext(); var exitingPromo = context.Promos.Find(Promo.ID); context.Entry(exitingPromo).CurrentValues.SetValues(Promo); context.SaveChanges(); }
public bool DeletePromo(int ID) { using (var context = new eCommerceContext()) { var promo = context.Promos.Find(ID); context.Promos.Remove(promo); return(context.SaveChanges() > 0); } }