예제 #1
0
        public ResultDto Add(RequestAddSellerProductDto request)
        {
            #region Validate Enteries
            if (request.CatId == 0)
            {
                return(new ResultDto()
                {
                    IsSuccess = false,
                    Message = "!دسته بندی را انتخاب نمایید",
                });
            }

            if (request.ProductId == 0)
            {
                return(new ResultDto()
                {
                    IsSuccess = false,
                    Message = "!محصول را انتخاب نمایید",
                });
            }
            if (request.Inventory == 0)
            {
                return(new ResultDto()
                {
                    IsSuccess = false,
                    Message = "!تعداد موجودی را وارد نمایید",
                });
            }
            if (request.SellerPrice == 0)
            {
                return(new ResultDto()
                {
                    IsSuccess = false,
                    Message = "!قیمت محصول را نمایید",
                });
            }
            #endregion

            SellerProduct _selllerproduct = new SellerProduct()
            {
                Inventory   = request.Inventory,
                ProductId   = request.ProductId,
                SellerId    = _context.Sellers.SingleOrDefault(s => s.UserId == request.SellerId.ToString() && s.CategoryId == request.CatId).Id,
                SellerPrice = request.SellerPrice,
            };
            _context.SellerProducts.Add(_selllerproduct);
            _context.SaveChanges();
            return(new ResultDto
            {
                IsSuccess = true,
                Message = "کالا با موفقیت  به لیست فروشگاه شمااضافه شد",
            });
        }
예제 #2
0
        public ResultDto Add(RequestAddNewSellerDto request)
        {
            var seller = new eshop.Domain.Entities.Sellers.Seller
            {
                UserName = request.UserName,
                //Addrress = request.Addrress,
                IsActive = true,
                Mobile   = request.Mobile,
                //Phone = request.Phone,
                //CityId = request.CityId,
                ShopName = request.ShopName,
                Category = _context.Categories.SingleOrDefault(n => n.Id == request.CategoryId),
                UserId   = request.UserId,
            };

            try
            {
                _context.Sellers.Add(seller);
                _context.SaveChanges();
                return(new ResultDto()
                {
                    IsSuccess = true,
                    Message = "!ثبت نام با موفقیت انجام شد",
                });
            }
            catch (Exception ex)
            {
                return(new ResultDto()
                {
                    IsSuccess = false,
                    Message = ex.ToString(),
                });
            }
        }
예제 #3
0
        public ResultDto <ResultPaymentDto> Execute(int Amount, string UserId)
        {
            var     user     = _context.Users.Find(UserId);
            Payment Payment1 = new Payment()
            {
                Guid    = Guid.NewGuid(),
                Amount  = Amount,
                User    = user,
                IsPayed = false,
            };

            _context.Payments.Add(Payment1);
            _context.SaveChanges();
            return(new ResultDto <ResultPaymentDto>()
            {
                Data = new ResultPaymentDto
                {
                    Guid = Payment1.Guid,
                    Amount = Payment1.Amount,
                    Email = user.Email,
                    PaymentId = Payment1.Id,
                },
                IsSuccess = true,
            });
        }
예제 #4
0
        public ResultDto Execute(int?ParentId, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(new ResultDto
                {
                    IsSuccess = false,
                    Message = "نام را وارد کنید",
                });
            }

            SCategory sCategory = new SCategory
            {
                Name           = name,
                ParentCategory = _context.SCategories.Find(ParentId),
            };

            _context.SCategories.Add(sCategory);
            _context.SaveChanges();
            return(new ResultDto
            {
                IsSuccess = true,
                Message = "دسته بندی با موفقیت اضافه گردید",
            });
        }
        public ResultDto Execute(int?ParentId, string Name)
        {
            if (String.IsNullOrWhiteSpace(Name))
            {
                return(new ResultDto()
                {
                    IsSuccess = false,
                    Message = "نام دسته بندی ",
                });
            }

            var Category1 = new Category()
            {
                Name           = Name,
                ParentCategory = GetParent(ParentId),
                //ParentCategoryId=ParentId,
            };

            _context.Categories.Add(Category1);
            _context.SaveChanges();
            return(new ResultDto()
            {
                IsSuccess = true,
                Message = "دسته بندی با موفقیت اضافه گردید",
            });
        }
예제 #6
0
 protected void ExecuteCommandInternal(Action <IDataBaseContext> action)
 {
     using (_context)
     {
         action(_context);
         _context.SaveChanges();
     }
 }
예제 #7
0
        public ResultDto Add(int CartItemId)
        {
            var cartItem = _context.CartItems.Find(CartItemId);

            cartItem.Count++;

            _context.SaveChanges();
            return(new ResultDto()
            {
                IsSuccess = true,
            });
        }
예제 #8
0
        public ResultDto Execute(RequestAddNewOrderDto request)
        {
            var user       = _context.Users.Find(request.UserId);
            var requestPay = _context.Payments.Find(request.PaymentId);
            var cart       = _context.Carts
                             .Include(c => c.CartItems)
                             .ThenInclude(c => c.SellerProduct)
                             .ThenInclude(c => c.Product)
                             .Where(c => c.Id == request.CartId).FirstOrDefault();

            requestPay.IsPayed   = true;
            requestPay.RefId     = request.RefId;
            requestPay.Authority = request.Authority;
            requestPay.PayDate   = DateTime.Now;
            cart.Finished        = true;

            var order = new Order
            {
                User       = user,
                Payment    = requestPay,
                OrderState = OrderState.Processing,
                Addrress   = "",
            };

            _context.Orders.Add(order);

            List <OrderDetail> OrderDetails = new List <OrderDetail>();

            foreach (var item in cart.CartItems)
            {
                var orderDetail = new OrderDetail
                {
                    Product       = item.Product,
                    Count         = item.Count,
                    Order         = order,
                    Price         = item.SellerProduct.SellerPrice,
                    SellerProduct = item.SellerProduct,
                };
                OrderDetails.Add(orderDetail);
            }

            _context.OrderDetails.AddRange(OrderDetails);
            _context.SaveChanges();

            return(new ResultDto
            {
                IsSuccess = true,
                Message = "!",
            });
        }
예제 #9
0
        public ResultDto Execute(string UserId)
        {
            var user = _context.Users.SingleOrDefault(u => u.Id == UserId);

            if (user == null)
            {
                return(new ResultDto()
                {
                    IsSuccess = false,
                    Message = "کاربر یافت نشد",
                });
            }

            user.IsDeleted = true;
            _context.SaveChanges();
            return(new ResultDto()
            {
                IsSuccess = true,
                Message = "کاربر حذف گردید"
            });
        }
예제 #10
0
        public ResultDto Execute(RequestEditUserDto request)
        {
            var User1 = _context.Users.Find(request.UserId);

            if (User1 == null)
            {
                new ResultDto()
                {
                    IsSuccess = false,
                    Message   = "کاربر یافت نشد !"
                };
            }

            User1.FullName = request.FullName;
            User1.Email    = request.Email;
            _context.SaveChanges();

            return(new ResultDto()
            {
                IsSuccess = true,
                Message = "عملیات ویرایش انجام شد",
            });
        }
        public ResultDto Execute(int UserId)
        {
            var User1 = _context.Users.Find(UserId);

            if (User1 == null)
            {
                return(new ResultDto()
                {
                    IsSuccess = false,
                    Message = "کاربر یافت نشد !",
                });
            }

            User1.IsActive = !User1.IsActive;
            _context.SaveChanges();

            string Str_userstate = User1.IsActive == true ? "فعال" : "غیرفعال";

            return(new ResultDto()
            {
                IsSuccess = true,
                Message = $"کاربر با موفقیت {Str_userstate} شد!"
            });
        }
예제 #12
0
 /// <summary>
 /// Saves changes to the DbContext.
 /// </summary>
 public void Save()
 {
     _dbContext.SaveChanges();
 }
예제 #13
0
        public ResultDto <ProductDetailForeSiteDto> Execute(int Id)
        {
            var product = _context.Products
                          .Include(p => p.Category)
                          .ThenInclude(p => p.ParentCategory)
                          .Include(p => p.SellerProducts)
                          .ThenInclude(p => p.Seller)
                          .Include(p => p.ProductImages)
                          .Include(p => p.ProductFeatures)
                          .FirstOrDefault(p => p.Id == Id);

            if (product == null)
            {
                new ResultDto
                {
                    IsSuccess = false,
                    Message   = "!محصولی یافت نشد",
                };
            }

            product.ViewCount++;
            _context.SaveChanges();

            if (product.SellerProducts.Where(s => s.Inventory > 0).FirstOrDefault() == null)
            {
                return(new ResultDto <ProductDetailForeSiteDto>
                {
                    Data = new ProductDetailForeSiteDto
                    {
                        Id = product.Id,
                        Brand = product.Brand,
                        Category = $"{product.Category.ParentCategory.Name} - {product.Category.Name}",
                        Description = product.Description,
                        Name = product.Name,
                        ImagesSrc = product.ProductImages.Select(p => p.Src).ToList(),
                        Features = product.ProductFeatures.Select(p => new ProductDetailForeSite_FeaturesDto
                        {
                            DisplayName = p.DisplayName,
                            Value = p.Value,
                        }).ToList(),
                    },
                });
            }
            //------add one to number of visited-----


            return(new ResultDto <ProductDetailForeSiteDto>
            {
                Data = new ProductDetailForeSiteDto
                {
                    Id = product.Id,
                    Brand = product.Brand,
                    Category = $"{product.Category.ParentCategory.Name} - {product.Category.Name}",
                    Description = product.Description,
                    Name = product.Name,
                    SellerId = product.SellerProducts.OrderBy(s => s.SellerPrice).FirstOrDefault().SellerId,
                    SellerName = product.SellerProducts.OrderBy(s => s.SellerPrice).FirstOrDefault().Seller.ShopName,
                    SellerPrice = product.SellerProducts.OrderBy(s => s.SellerPrice).FirstOrDefault().SellerPrice,
                    UserName = product.SellerProducts.OrderBy(s => s.SellerPrice).FirstOrDefault().Seller.UserName,
                    ImagesSrc = product.ProductImages.Select(p => p.Src).ToList(),
                    Features = product.ProductFeatures.Select(p => new ProductDetailForeSite_FeaturesDto
                    {
                        DisplayName = p.DisplayName,
                        Value = p.Value,
                    }).ToList(),
                    ProdustSellers = product.SellerProducts.Where(sp => sp.Inventory > 0).Select(sp => new ProdustSellersDto()
                    {
                        SellerId = sp.Seller.Id,
                        SellerName = sp.Seller.ShopName,
                        SellerPrice = sp.SellerPrice,
                        ProductId = sp.ProductId,
                        UserName = sp.Seller.UserName,
                    }).OrderBy(p => p.SellerPrice).ToList(),
                },
                IsSuccess = true,
                Message = "",
            });
        }