public async Task <ApiResult <List <TagDto> > > Get(CancellationToken cancellationToken) { var list = await _repositoryPostTag.TableNoTracking .Where(a => !a.VersionStatus.Equals(2)) .GroupBy(a => a.TagId) .Select(g => new { g.Key, Count = g.Count() }) .OrderByDescending(a => a.Count) .Take(20) .ToListAsync(cancellationToken); var result = new List <TagDto>(); foreach (var value in list) { var res = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && a.Id.Equals(value.Key)) .ProjectTo <TagDto>(Mapper.ConfigurationProvider) .SingleOrDefaultAsync(cancellationToken); if (res == null) { continue; } result.Add(res); } return(result); }
/// <summary> /// تغییر وضعیت یک فاکتور /// در صورتی که فاکتور در در ایتدای کار باشد یعنی پرداخت شده باشد باید در وضعیت ثبت سفارش قرار بگیرد /// در غیر اینصورت باید به مرحله بعدی برود /// در صورتی که در مرحله تحویل باشد /// دیگر نمیتوان وضعیت آن را تغییر داد /// </summary> /// <param name="shopOrderId"></param> /// <returns></returns> public async Task <Tuple <SweetAlertExtenstion, ShopOrderStatusSSOT> > SendNextStatus(int shopOrderId) { var result = await TableNoTracking.Where(x => x.ShopOrderId == shopOrderId).OrderBy(x => x.Date).ToListAsync(); // حالتی که فاکتور تازه ثبت شده است یعنی به عبارت دیگر پرداخت توسط مشتری انجام شده است if (result == null || result.Count == 0) { return(new Tuple <SweetAlertExtenstion, ShopOrderStatusSSOT>(await this.InsertAsync(new ShopOrderStatusInsertViewModel { ShopOrderId = shopOrderId, Status = ShopOrderStatusSSOT.Ordered }), ShopOrderStatusSSOT.Ordered)); } var lastStatus = result.LastOrDefault().Status; if (lastStatus == ShopOrderStatusSSOT.Delivery) { return(new Tuple <SweetAlertExtenstion, ShopOrderStatusSSOT>(SweetAlertExtenstion.Error("فاکتور مورد نظر در مرحله تحویل است."), ShopOrderStatusSSOT.Nothing)); } return(new Tuple <SweetAlertExtenstion, ShopOrderStatusSSOT>(await this.InsertAsync(new ShopOrderStatusInsertViewModel { ShopOrderId = shopOrderId, Status = lastStatus + 1 }), lastStatus + 1)); }
/// <summary> /// Find localized value /// </summary> /// <param name="entityName">Entity name</param> /// <param name="propertyName">Property name</param> /// <param name="entityId">Entity identifier</param> /// <param name="languageId">Language identifier</param> /// <param name="loadAllLocalizedProperties">true => load all records form cache | false => gradual loading</param> /// <returns>return localized value as string</returns> public virtual Task <string> GetLocalizedValueAsync(string entityName, string propertyName, int entityId, int languageId, bool loadAllLocalizedProperties, CancellationToken cancellationToken = default) { if (languageId == 0) { throw new ArgumentOutOfRangeException(nameof(languageId), "Language ID should not be 0"); } var key = string.Format(LocalizationCacheKeys.LocalizedPropertyCacheKey, entityName, entityId, propertyName, languageId); return(_cacheManagerString.GetAsync(key, LocalizationCacheKeys.LocalizedPropertyCacheRegion, async() => { string localeValue; if (loadAllLocalizedProperties) { //load all records (we know they are cached) var source = await GetAllCachedAsync(cancellationToken); localeValue = source .Where(p => p.LanguageId == languageId && p.EntityId == entityId && p.EntityName == entityName && p.PropertyName == propertyName) .Select(p => p.LocaleValue).FirstOrDefault(); } else { //gradual loading localeValue = await TableNoTracking .Where(p => p.LanguageId == languageId && p.EntityId == entityId && p.EntityName == entityName && p.PropertyName == propertyName) .Select(p => p.LocaleValue).FirstOrDefaultAsync(cancellationToken); } //little hack here. nulls aren't cacheable so set it to "" return localeValue ?? ""; })); }
public bool HasAccess(int roleId, string controller, string action) /*=> true;*/ { var roleName = _roleRepository.GetRoleNameByRoleId(roleId); if (roleName == ImportantNames.AdminNormalTitle()) { return(true); } var userAccess = TableNoTracking.Where(a => a.RoleId == roleId).ToList(); foreach (var item in userAccess) { if (item.Controller.ToUpper() == controller.ToUpper() + ImportantNames.ControllerName()) { var actions = item.Actions == null ? null : JsonConvert.DeserializeObject <List <string> >(item.Actions); if (actions != null && actions.Contains(action)) { return(true); } } } return(false); }
public PagedList <Category> GetPaged(IPaged paged) { return(TableNoTracking .Where(p => p.ParentId == null) .Include(p => p.Categories) .PagedList(paged.PageIndex, paged.PageSize, paged.SearchByPropertyName, paged.SearchByText, paged.OrderByPropertyName, paged.OrderByDescending)); }
public async Task <IEnumerable <Product> > GetListByCategoryAsync(CategoryType categoryType) { return(await TableNoTracking .Where(x => x.CategoryType == categoryType) .ToListAsync() .ConfigureAwait(false)); }
///TODO Use Generic Grid View public async Task <Tuple <int, List <CarsTransportaionsFullDto> > > GetAllCars(CarTransportationSearchViewModel model, int skip, int take) { var query = TableNoTracking.Where(a => !a.IsDeleted).ProjectTo <CarsTransportaionsFullDto>(); query = query.WhereIf(!string.IsNullOrEmpty(model.CarName), a => a.CarName.Contains(model.CarName)); query = query.WhereIf(!string.IsNullOrEmpty(model.CarModel), a => a.CarModel.Contains(model.CarModel)); query = query.WhereIf(!string.IsNullOrEmpty(model.MotorSerial), a => a.MotorSerial.Contains(model.MotorSerial)); query = query.WhereIf(!string.IsNullOrEmpty(model.Plaque), a => a.Plaque.Contains(model.Plaque)); query = query.WhereIf(model.TransportSize != null, a => a.TransportSize == model.TransportSize); 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 <CarsTransportaionsFullDto> >(Count, await query.ToListAsync())); }
/// <summary> /// </summary> /// <param name="predicate"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public IPageList <UserSkill> GetPageList(Expression <Func <UserSkill, bool> > predicate, int pageIndex = 1, int pageSize = 8) { var query = TableNoTracking.Where(predicate); var pages = query.Skip((pageIndex - 1) * pageSize).Take(pageSize); return(new PageList <UserSkill>(pages, pageIndex, pageSize)); }
/// <summary> /// گرفتن تمام فرزندان یک پدر تا یک سطح /// </summary> /// <param name="parentId">شماره پدر</param> /// <param name="includeItSelf">خروجی مورد نظر شامل خود پدر هم بشود یا نه</param> /// <returns></returns> public async Task <List <ProductGroupDTO> > GetByParentId(int parentId, bool includeItSelf = false) { if (!includeItSelf) { return(await TableNoTracking.Where(x => x.ParentId == parentId).ProjectTo <ProductGroupDTO>().ToListAsync()); } //شامل خودش return(await TableNoTracking.Where(x => x.ParentId == parentId || x.Id == parentId).ProjectTo <ProductGroupDTO>().ToListAsync()); }
/// <summary> /// زمانی دسترسی های نقشی تغییر پیدا میکند ابتدا باید تمامی نقش های آن پاک شود /// </summary> /// <param name="roleId"></param> public void RemoveAccessRole(int roleId) { var lstAccessRole = TableNoTracking.Where(a => a.RoleId == roleId); if (lstAccessRole.Any()) { DeleteRange(lstAccessRole); } }
public async Task UpdateRemindedGallery(List <int> remindedGallery, int productId) { var productGallery = await TableNoTracking.Where(a => a.ProductId == productId && !remindedGallery.Contains(a.Id)).ToListAsync(); DeletePic(productGallery.Select(x => x.Pic).ToList()); await DeleteRangeAsync(productGallery); }
public async Task <ApiResult <List <LikeDto> > > Get(int userId, CancellationToken cancellationToken) { var list = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && a.UserId.Equals(userId)) .ProjectTo <LikeDto>(Mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(list); }
public async Task <ApiResult <List <CategoryDto> > > GetAllByCatId(int id, CancellationToken cancellationToken) { var list = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && a.ParentCategoryId.Equals(id)) .ProjectTo <CategoryDto>(Mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(list); }
public async Task <ApiResult <List <CategoryWithSubCatDto> > > GetCategoryWithSub(CancellationToken cancellationToken) { var list = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && a.ParentCategoryId.Equals(0) || a.ParentCategoryId == null) .Include(a => a.ChildCategories) .ProjectTo <CategoryWithSubCatDto>(Mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(list); }
public async Task <DateTimeOffset> Create(CommentDto dto, CancellationToken cancellationToken) { var lastComment = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && a.PostId.Equals(dto.PostId) && a.UserId.Equals(dto.UserId)) .OrderByDescending(a => a.Time) .Select(a => a.Time) .FirstAsync(cancellationToken); return(lastComment); }
public async Task <ApiResult <List <PostShortSelectDto> > > GetByUserId(CancellationToken cancellationToken, int id) { var list = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && a.UserId.Equals(id)) .ProjectTo <PostShortSelectDto>(Mapper.ConfigurationProvider) .Take(DefaultTake) .ToListAsync(cancellationToken); return(list); }
/// <summary> /// </summary> /// <param name="userId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public IPageList <UserProject> GetPageListByUserId(long userId, int pageIndex = 1, int pageSize = 8) { var query = TableNoTracking.Where(n => n.UserId == userId); query = query.OrderByDescending(n => n.StartDate); var list = query.ToPagedList(pageIndex, pageSize); return(list); }
public async Task <PagerList <TEntity> > PagerQueryAsNoTrackingAsync(IQueryBase <TEntity> query) { var order = query.GetOrder(); if (string.IsNullOrWhiteSpace(order)) { order = "Id"; } return(TableNoTracking.Where(query).OrderBy(order).ToPagerList(query.GetPager())); }
public async Task <ApiResult <List <EmploySelectDto> > > Get(CancellationToken cancellationToken) { var list = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2)) .OrderByDescending(a => a.Time) .ProjectTo <EmploySelectDto>(Mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(list); }
/// <summary> /// تغییر وضعیت سبد خرید /// مشخص کردن فاکتور /// </summary> /// <param name="list"></param> /// <param name="orderId"></param> /// <returns></returns> public async Task <bool> ChangeStatus(int orderId) { var model = await TableNoTracking.Where(a => a.ShopOrderId == orderId).ToListAsync(); model.ForEach(a => { a.IsFactorSubmited = true; }); await UpdateRangeAsync(model, false); return(Save()); }
public async Task <List <BlogCategory> > GetByIsActive() { try { return(await TableNoTracking.Where(x => x.IsActive).Include(x => x.Blogs).ToListAsync()); } catch (Exception ex) { throw; } }
public async Task <ApiResult <List <PostShortSelectDto> > > GetAllByCatId(CancellationToken cancellationToken, int id, int to = 0) { var list = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && a.CategoryId.Equals(id)) .OrderByDescending(a => a.Time) .ProjectTo <PostShortSelectDto>(Mapper.ConfigurationProvider) .Take(DefaultTake + to) .ToListAsync(cancellationToken); return(list); }
public async Task <ApiResult <List <PostShortSelectDto> > > Search(CancellationToken cancellationToken, string str) { Assert.NotNullArgument(str, "کلمه مورد جستجو نامعتبر است"); var list = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && a.Title.Contains(str)) .OrderByDescending(a => a.Time) .ProjectTo <PostShortSelectDto>(Mapper.ConfigurationProvider) .Take(DefaultTake) .ToListAsync(cancellationToken); return(list); }
public async Task <ICollection <WeaponItemProperty> > GetWeaponItemByItemIdCollection(ICollection <int> items) { return(await TableNoTracking .Where(e => items.Contains(e.ItemId)) .Include(e => e.Item) .ThenInclude(item => item.Product) .ThenInclude(article => article.Category) .Include(e => e.Item) .ThenInclude(item => item.Product) .ThenInclude(article => article.Effects) .Include(e => e.AdditionalDamages) .ToListAsync() .ConfigureAwait(false)); }
public async Task <ApiResult <List <TagDto> > > GetPostTag(int id, CancellationToken cancellationToken) { var list = await _repositoryPostTag.TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && a.PostId.Equals(id)) .Select(a => a.TagId) .ToListAsync(cancellationToken); var result = await TableNoTracking .Where(a => !a.VersionStatus.Equals(2) && list.Contains(a.Id)) .ProjectTo <TagDto>(Mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(result); }
public async Task <ICollection <Weapon> > GetDistinctCollectionByArticles(ICollection <int> articlesId) { return(await TableNoTracking .Where(weapon => articlesId.Contains(weapon .Product.Id)) .Include(e => e.Product) .Include(e => e.Ammunition) .Include(e => e.DamageTypeList) .Include(e => e.MediumSizeDamage) .Include(e => e.WeaponType) .ThenInclude(weaponType => weaponType.WeaponProficiency) .Include(e => e.SmallSizeDamage) .ToListAsync()); }
/// <summary> /// </summary> /// <param name="userId"></param> /// <param name="predicate"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public IPageList <UserSkill> GetPageListByUserId(long userId, Expression <Func <UserSkill, bool> > predicate = null, int pageIndex = 1, int pageSize = 15) { var query = TableNoTracking.Where(n => n.UserId == userId); if (predicate != null) { query = query.Where(predicate); } query = query.OrderByDescending(n => n.CreateTime); var list = query.ToPagedList(pageIndex, pageSize); return(list); }
/// <summary> /// زمانی دسترسی های نقشی تغییر پیدا میکند ابتدا باید تمامی نقش های آن پاک شود /// </summary> /// <param name="roleId"></param> public async Task <bool> RemoveAccessRole(int roleId) { try { var lstAccessRole = await TableNoTracking.Where(a => a.RoleId == roleId).ToListAsync(); if (lstAccessRole.Any()) { DeleteRange(lstAccessRole); } return(true); } catch (Exception e) { return(false); } }
public async Task <Tuple <int, List <ShopOrder> > > OrderLoadAsync(ShopOrdersSearchViewModel vm, int page = 0, int pageSize = 10) { var model = TableNoTracking.Where(a => !a.IsDeleted); model = model.WhereIf(vm.Id != null, a => a.Id == vm.Id); model = model.WhereIf(vm.Amount != null, a => a.Amount == vm.Amount); model = model.WhereIf(vm.Status != null, a => a.Status == vm.Status); model = model.WhereIf(vm.IsSuccessed != null, a => a.IsSuccessed == vm.IsSuccessed); var count = model.Count(); model = model.Include(a => a.Users); model = model.OrderByDescending(a => a.CreateDate).ThenByDescending(a => a.Id); return(new Tuple <int, List <ShopOrder> >(count, await model.Skip((page - 1) * pageSize).Take(pageSize).ToListAsync())); }
public async Task <long> ResultPrice(int packageId) { var model = await TableNoTracking .Where(a => a.PackageId == packageId) .Include(a => a.Product) .ToListAsync(); var sum = default(long); foreach (var item in model) { sum += await _productRepostitory.ResultPrice(item.ProductId); } return(sum); }