public bool HasAccess(int role, IDictionary <string, string> path) { var roleName = _roleRepository.GetRoleNameByRoleId(role); if (roleName == ImportantNames.AdminNormalTitle()) { return(true); } var userAccess = TableNoTracking.Include(a => a.Roles).Where(a => a.Roles.Id == role).ToList(); foreach (var item in userAccess) { if (item.Controller.ToUpper() == path["controller"].ToUpper() + ImportantNames.ControllerName()) { var actions = item.Actions == null ? null : JsonConvert.DeserializeObject <List <string> >(item.Actions); if (actions != null && actions.Contains(path["action"])) { return(true); } } } return(false); }
public async Task <Tuple <int, List <TransportationTariffFullDto> > > GetAllTariff(TariffSearchViewModel model, int skip, int take) { var query = TableNoTracking.Include(a => a.CarTransport).Where(a => !a.IsDeleted).ProjectTo <TransportationTariffFullDto>(); query = query.WhereIf(!string.IsNullOrEmpty(model.CarName), a => a.CarTransportCarName.Contains(model.CarName)); query = query.WhereIf(model.TehranAreasFrom != null, a => a.TehranAreasFrom == model.TehranAreasFrom); query = query.WhereIf(model.TehranAreasTO != null, a => a.TehranAreasTO == model.TehranAreasTO); query = query.WhereIf(model.ProductSizeTo != null, a => a.ProductSizeTo == model.ProductSizeTo); query = query.WhereIf(model.ProductSizeFrom != null, a => a.ProductSizeFrom == model.ProductSizeFrom); query = query.WhereIf(model.Tariff != null, a => a.Tariff == model.Tariff); int Count = query.Count(); query = query.OrderByDescending(x => x.Id); if (skip != -1) { query = query.Skip((skip - 1) * take); } if (take != -1) { query = query.Take(take); } return(new Tuple <int, List <TransportationTariffFullDto> >(Count, await query.ToListAsync())); }
/// <summary> /// گرفتن اطلاعات ویژگی های محصول بر اساس شناسه محصول /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <List <ProductFeature> > GetFeaturesByProductId(int id) { var model = await TableNoTracking.Include(a => a.Feature) .Where(a => a.ProductId == id).ToListAsync(); return(model); }
private IQueryable <Person> GetWithIncludes() { return(TableNoTracking .Include(p => p.City) .Include(p => p.PhoneNumbers) .Include(p => p.Relations) .ThenInclude(r => r.RelatedPerson)); }
public List <ShopProduct> ShopProductByUserId(int userId) { var model = TableNoTracking .Include(a => a.Product) .Include(a => a.ProductPackage) .Where(a => a.UserId == userId && a.IsFinaly == false && !a.IsFactorSubmited).ToList(); return(model); }
/// <summary> /// گرفتن اطلاعات محصول بر اساس شناسه برا نمایش جزِئیات محصول /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ProductFullDTO> GetProductDetail(int id) { var model = await TableNoTracking .Include(a => a.ProductGroup) .Where(a => a.Id == id && !a.IsDeleted) .ProjectTo <ProductFullDTO>() .FirstOrDefaultAsync(); return(model); }
/// <summary> /// محاسبه قیمت کلی محصول /// </summary> /// <param name="packageId"></param> /// <returns></returns> public async Task <string> CalculatePrice(int packageId) { try { var model = await TableNoTracking.Include(a => a.Product).Where(a => a.PackageId == packageId) .SumAsync(a => a.Product.Price); return(model.ToString("n0")); } catch (Exception) { return(null); } }
/// <summary> /// بررسی دوباره قیمت محصولات و ویرایش آن در سبد خرید /// </summary> /// <returns></returns> public async Task <SweetAlertExtenstion> ProductsPriceCheck(int invoiceId) { var model = await TableNoTracking.Include(a => a.Product).Where(a => a.ShopOrderId == invoiceId).ToListAsync(); model.ForEach(a => { a.OrderPrice = a.Product.Price.ToString(); a.OrderPriceDiscount = a.Product.PriceWithDiscount.ToString(); }); await UpdateRangeAsync(model, false); var entity = await DbContext.ShopOrder.SingleOrDefaultAsync(x => x.Id == invoiceId); //entity.Amount = model.Sum(x => Convert.ToInt64(x.OrderPriceDiscount)); entity.Amount = await CalculateCartPriceNumberWithoutUserId(invoiceId); entity.PaymentAmount = entity.Amount; await DbContext.SaveChangesAsync(); return(await SaveAsync()); }
/// <summary> /// ایجاد دوباره سبد خرید برای فاکتور /// </summary> /// <param name="ids"></param> /// <returns></returns> public async Task <SweetAlertExtenstion> OverwriteShopProduct(int invoiceId, int orderId, int?userId = null) { var model = await TableNoTracking.Include(a => a.Product).Where(a => a.ShopOrderId == invoiceId).ToListAsync(); foreach (var item in model) { await AddAsync(new ShopProduct() { Count = item.Count, IsFactorSubmited = true, ShopOrderId = orderId, IsFinaly = false, OrderName = item.OrderName, OrderPrice = item.Product.Price.ToString(), OrderPriceDiscount = item.Product.PriceWithDiscount.ToString(), ProductId = item.ProductId, UserId = userId != null ? userId.Value : item.UserId, RequestedDate = DateTime.Now, }, false); } return(await SaveAsync()); }
public async Task <Tuple <int, List <DataLayer.Entities.Product> > > GetProductsDiscount(ProductSearchListViewModel vm, int skip, int take) { var model = TableNoTracking .Include(a => a.ProductGroup) .Where(a => a.IsActive == true && !a.IsDeleted && a.Price != a.PriceWithDiscount); if (vm.Group != null && vm.Group != -1) { string sql = @" declare @T table(Id int); with A as ( select Id, ParentId from ProductGroup where Id = " + vm.Group.Value + @" union all select c.Id, c.ParentId from ProductGroup c join A p on p.Id = c.ParentId) select Id from A"; var result = await _connection.QueryMultipleAsync(sql); var groupsId = await result.ReadAsync <int>(); model = model .WhereIf(!string.IsNullOrEmpty(vm.Title), a => a.Title.Contains(vm.Title) || a.ShortDescription.Contains(vm.Title) || a.Text.Contains(vm.Title) || a.Tags.Contains(vm.Title)) //.WhereIf(vm.Group != null && vm.Group != -1, a => a.ProductGroupId.Equals(vm.Group.Value)) .WhereIf(vm.Group != null && vm.Group != -1, a => groupsId.Contains(a.ProductGroupId)) .WhereIf(vm.MaxPrice != null && vm.MinPrice != null, a => a.Price >= long.Parse(vm.MinPrice) && a.Price <= long.Parse(vm.MaxPrice)); } else { model = model .WhereIf(!string.IsNullOrEmpty(vm.Title), a => a.Title.Contains(vm.Title) || a.ShortDescription.Contains(vm.Title) || a.Text.Contains(vm.Title) || a.Tags.Contains(vm.Title)) .WhereIf(vm.MaxPrice != null && vm.MinPrice != null, a => a.Price >= long.Parse(vm.MinPrice) && a.Price <= long.Parse(vm.MaxPrice)); } var count = model.Count(); if (skip != 0) { model = model.Skip((skip - 1) * take); } if (take != 0) { model = model.Take(take); } return(new Tuple <int, List <DataLayer.Entities.Product> >(count, await model.ToListAsync())); }
public async Task <ShopOrder> GetItemByIdWithUserAsync(int Id) { return(await TableNoTracking.Include(x => x.Users).Where(x => x.Id == Id).SingleOrDefaultAsync()); }
// /// <summary> // /// ثبت یک آیتم در جدول مورد نظر // /// </summary> // /// <param name="model">مدلی که از سمت کلاینت در حال پاس دادن آن هستیم</param> // /// <returns></returns> // public async Task<SweetAlertExtenstion> UpdateAsync(ProductGroupUpdateViewModel model) // { // try // { // var entity = Mapper.Map<ProductGroup>(model); // await UpdateAsync(entity); // return SweetAlertExtenstion.Ok(); // } // catch // { // return SweetAlertExtenstion.Error(); // } // } // /// <summary> // /// ثبت یک آیتم در جدول مورد نظر // /// </summary> // /// <param name="model">مدلی که از سمت کلاینت در حال پاس دادن آن هستیم</param> // /// <returns></returns> // public async Task<SweetAlertExtenstion> DeleteAsync(int Id) // { // try // { // var entity = new ProductGroup { Id = Id }; // await DeleteAsync(entity); // return SweetAlertExtenstion.Ok("عملیات با موفقیت انجام شد"); // } // catch // { // return SweetAlertExtenstion.Error(); // } // } //} /// <summary> /// تمامی ویژگی های گروه یک محصول /// </summary> /// <returns></returns> public async Task <List <ProductGroupFeature> > GetAllProductGroupFeature(int groupId) => await TableNoTracking.Include(a => a.Feature).Where(a => a.ProductGroupId == groupId).ToListAsync();
public override async Task <Product> GetByIdAsync(int id) { return(await TableNoTracking.Include(e => e.Category).FirstOrDefaultAsync().ConfigureAwait(false)); }
public async Task <List <Feature> > GetFeaturesByListFeatureId(List <int> featureIds) => await TableNoTracking.Include(a => a.Features).Where(a => featureIds.Contains(a.Id)).ToListAsync();