Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public Category GetCategoryByID(int ID)
 {
     using (var context = new eCommerceContext())
     {
         return(context.Categories.Find(ID));
     }
 }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
 public Supplier GetSupplierByID(int ID)
 {
     using (var context = new eCommerceContext())
     {
         return(context.Suppliers.Find(ID));
     }
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        public void UpdateConfiguration(Configuration configuration)
        {
            eCommerceContext context = new eCommerceContext();

            context.Entry(configuration).State = System.Data.Entity.EntityState.Modified;

            context.SaveChanges();
        }
Exemplo n.º 10
0
        public void UpdateCategory(Category category)
        {
            eCommerceContext context = new eCommerceContext();

            context.Entry(category).State = System.Data.Entity.EntityState.Modified;

            context.SaveChanges();
        }
Exemplo n.º 11
0
        public bool SaveOrder(Order order)
        {
            eCommerceContext context = new eCommerceContext();

            context.Orders.Add(order);

            return(context.SaveChanges() > 0);
        }
Exemplo n.º 12
0
        public void UpdateSupplier(Supplier supplier)
        {
            eCommerceContext context = new eCommerceContext();

            context.Entry(supplier).State = System.Data.Entity.EntityState.Modified;

            context.SaveChanges();
        }
Exemplo n.º 13
0
        public void SaveSupplier(Supplier supplier)
        {
            eCommerceContext context = new eCommerceContext();

            context.Suppliers.Add(supplier);

            context.SaveChanges();
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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());
        }
Exemplo n.º 16
0
        public void SaveProduct(Product Product)
        {
            eCommerceContext context = new eCommerceContext();

            context.Products.Add(Product);

            context.SaveChanges();
        }
Exemplo n.º 17
0
        public List <Product> GetDataEntryProducts(string sentUserId)
        {
            eCommerceContext context = new eCommerceContext();

            var Products = context.Products.Where(x => x.UserId == sentUserId).ToList();

            return(Products);
        }
Exemplo n.º 18
0
        public List <CountryCode> GetCountryCodes()
        {
            eCommerceContext context = new eCommerceContext();

            var codes = context.CountryCodes.ToList();

            return(codes);
        }
Exemplo n.º 19
0
        public bool AddComment(Comment comment)
        {
            eCommerceContext context = new eCommerceContext();

            context.Comments.Add(comment);

            return(context.SaveChanges() > 0);
        }
Exemplo n.º 20
0
        public void SaveCategory(Category category)
        {
            eCommerceContext context = new eCommerceContext();

            context.Categories.Add(category);

            context.SaveChanges();
        }
Exemplo n.º 21
0
        public eCommerceUser GetUserById(string Id)
        {
            eCommerceContext context = new eCommerceContext();

            var user = context.Users.Find(Id);

            return(user);
        }
Exemplo n.º 22
0
        public eCommerceUser GetUserByUsername(string Username)
        {
            eCommerceContext context = new eCommerceContext();

            var user = context.Users.Find(Username);

            return(user);
        }
Exemplo n.º 23
0
        public bool AddOrderHistory(OrderHistory orderHistory)
        {
            eCommerceContext context = new eCommerceContext();

            context.OrderHistories.Add(orderHistory);

            return(context.SaveChanges() > 0);
        }
Exemplo n.º 24
0
        public void SavePromo(Promo Promo)
        {
            eCommerceContext context = new eCommerceContext();

            context.Promos.Add(Promo);

            context.SaveChanges();
        }
Exemplo n.º 25
0
        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());
        }
Exemplo n.º 26
0
        public int SavePicture(Picture picture)
        {
            eCommerceContext context = new eCommerceContext();

            context.Pictures.Add(picture);

            context.SaveChanges();

            return(picture.ID);
        }
Exemplo n.º 27
0
        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());
        }
Exemplo n.º 28
0
        public Payment AddUserPayment(Payment payment)
        {
            eCommerceContext context = new eCommerceContext();

            var paymentToAdd = context.Payment.Add(payment);

            context.SaveChanges();

            return(paymentToAdd);
        }
Exemplo n.º 29
0
        public void UpdatePromo(Promo Promo)
        {
            eCommerceContext context = new eCommerceContext();

            var exitingPromo = context.Promos.Find(Promo.ID);

            context.Entry(exitingPromo).CurrentValues.SetValues(Promo);

            context.SaveChanges();
        }
Exemplo n.º 30
0
        public bool DeletePromo(int ID)
        {
            using (var context = new eCommerceContext())
            {
                var promo = context.Promos.Find(ID);

                context.Promos.Remove(promo);

                return(context.SaveChanges() > 0);
            }
        }