public Task <List <VendorProductViewModel> > GetVendorProducts(string userId, SearchProductViewModel searchProduct) { var shop = _context.Shops.Where(x => x.UserId == userId).FirstOrDefault(); string tblName = shop.tableName; var vendorProductsTable = new DataTable(); DateTime dateTime = DateTime.Now; List <VendorProductViewModel> products = new List <VendorProductViewModel>(); using (var command = _context.Database.GetDbConnection().CreateCommand()) { int totalSkip = searchProduct.PageSize * (searchProduct.PageNumber - 1); StringBuilder sbWhere = new StringBuilder(); sbWhere.Append($" where IsActive = true and shopId='{shop.Id}'"); if (!string.IsNullOrEmpty(searchProduct.ProductId)) { sbWhere.Append("and ProductId='").Append(searchProduct.ProductId).Append("' "); } else if (!string.IsNullOrEmpty(searchProduct.CategoryId) || !string.IsNullOrEmpty(searchProduct.BrandId)) { if (!string.IsNullOrEmpty(searchProduct.CategoryId)) { sbWhere.Append("and CategoryId='").Append(searchProduct.CategoryId).Append("' "); } if (!string.IsNullOrEmpty(searchProduct.SubCategoryId)) { sbWhere.Append("and SubCategoryId='").Append(searchProduct.SubCategoryId).Append("' "); } if (!string.IsNullOrEmpty(searchProduct.BrandId)) { sbWhere.Append("and BrandId='").Append(searchProduct.BrandId).Append("' "); } } var result = _context.VendorProducts.FromSqlRaw($"select Id,IsOutStock,ProductId,ProductName,ProductUrl,Selling,MRP,ItemCount,ExpiryDate,Discount,UnitId,Description from VendorProduct.Vendor{tblName}Products {sbWhere.ToString()} order by Id OFFSET {totalSkip} ROWS FETCH NEXT {searchProduct.PageSize} ROWS ONLY;") .Select(x => new VendorProductViewModel { Id = x.Id, ProductId = x.ProductId, ProductName = x.ProductName, Description = x.Description, Discount = x.Discount, IsOutStock = x.IsOutStock, MRP = x.MRP, ExpiryDate = x.ExpiryDate, ItemCount = x.ItemCount.Value, ProductUrl = _documentStorage.GetProductUri(x.ProductUrl).Result, Selling = x.Selling, UnitId = x.UnitId }).AsQueryable(); products = result.ToList(); } return(Task.FromResult(products)); }
public AutomapperProfiles() { this.jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; ImageKitClass documentStorage = new ImageKitClass(); CreateMap <Category, CategoryViewModel>().ReverseMap(); CreateMap <Shop, ShopViewModel>() .ForMember(dest => dest.ShopId, opt => opt.MapFrom(src => src.Id)) .ReverseMap(); CreateMap <SubCategory, SubCategoryViewModel>().ReverseMap(); CreateMap <Product, ProductViewModel>() .ForMember(dest => dest.ProductId, opt => opt.MapFrom(src => src.Id)) .ForMember(dest => dest.ImageUrl, opt => opt.MapFrom(src => documentStorage.GetProductUri(src.ImageUrl).Result)) .ReverseMap(); CreateMap <UserAddress, UserAddressViewModel>().ReverseMap(); CreateMap <UserAddress, AddressViewModel>().ReverseMap(); CreateMap <Shop, AddressViewModel>().ReverseMap(); CreateMap <OrderSummary, OrderSummaryViewModel>() .ForMember(dest => dest.OrderSummaryId, opt => opt.MapFrom(src => src.Id)) .ForMember(dest => dest.OrderDate, opt => opt.MapFrom(src => src.CreatedDateTime)) .ForMember(dest => dest.TotalAmount, opt => opt.MapFrom(src => (src.OrderStatusId == (int)EnumOrderStatus.PriceHiddenByShopper || src.OrderStatusId == (int)EnumOrderStatus.Cancel) ? 0:src.TotalAmount)) .ForMember(dest => dest.OrdersDetails, opt => opt.MapFrom(src => (src.OrderStatusId == (int)EnumOrderStatus.PriceHiddenByShopper || src.OrderStatusId == (int)EnumOrderStatus.Cancel)? GetOrderDetails(src.OrdersDetails):src.OrdersDetails)) .ReverseMap(); CreateMap <UserForListDto, User>().ReverseMap(); CreateMap <UserForRegisterViewModel, User>().ReverseMap(); CreateMap <BrandViewModel, Brand>().ReverseMap(); CreateMap <FavoriteShopViewModel, FavoriteShop>().ReverseMap(); }