public async Task <ActionResult <IBaseApiModel <string> > > GetCurrentUser(TypeModelResponseEnum modelResponseType) { var userId = GetUserId(); var user = await _service.GetAsync(userId, modelResponseType); return(SuccessResult(user)); }
protected IBaseApiModel <TKey> GetParsedResult(TEntity entity, TypeModelResponseEnum modelResponseType) { switch (modelResponseType) { case TypeModelResponseEnum.GetFullApiModel: return(_dataMapper.Parse <TEntity, TModelGetFull>(entity)); case TypeModelResponseEnum.GetMinApiModel: return(_dataMapper.Parse <TEntity, TModelGetMin>(entity)); default: return(_dataMapper.Parse <TEntity, TModelGetFull>(entity)); } }
public virtual async Task <IBaseApiModel <TKey> > GetAsync(TKey id, TypeModelResponseEnum modelResponseType, int?langId = null) { var type = typeof(TEntity); Expression <Func <TEntity, bool> > filter = null; if (type.GetInterface(typeof(IBaseLanguageEntity <TKey>).Name) != null && langId != null) { filter = x => ((IBaseLanguageEntity <TKey>)x).LanguageId.Equals(langId) && x.Id.Equals(id); } var entity = await _repository.GetAsync(id, filter); var model = GetParsedResult(entity, modelResponseType); return(model); }
public virtual async Task <ActionResult <IBaseApiModel <TKey> > > Get(TKey id, TypeModelResponseEnum modelResponseType) { var model = await _service.GetAsync(id, modelResponseType); return(SuccessResult(model)); }
public async Task <PaginationResponseApiModel <IBaseApiModel <string>, UserSortingEnum> > GetManagersAsync(int start, int count, List <UserSortingEnum> sortings, TypeModelResponseEnum modelResponseType, int langId) { var pagination = await _repository.GetManagersAsync(start, count, sortings, langId); var result = GetParsedPaginationResult(pagination.Entities, modelResponseType, pagination.Total, pagination.Start, pagination.Count, pagination.EntitySortings); return(result); }
public virtual async Task <PaginationResponseApiModel <IBaseApiModel <TKey>, TSorting> > GetAsync(int start, int count, List <TSorting> sortings, TypeModelResponseEnum modelResponseType, int?langId = null, string query = null) { CollectionOfEntities <TEntity, TSorting> pagination = null; var type = typeof(TEntity); List <Expression <Func <TEntity, bool> > > filters = new List <Expression <Func <TEntity, bool> > >(); if (type.GetInterface(typeof(IBaseLanguageEntity <TKey>).Name) != null && langId != null) { filters.Add(x => ((IBaseLanguageEntity <TKey>)x).LanguageId.Equals(langId)); } if (!string.IsNullOrEmpty(query) && type.GetInterface(typeof(IBaseManualEntity <TKey>).Name) != null) { var q = query.ToLower(); filters.Add(x => ((IBaseManualEntity <TKey>)x).Title != null && ((IBaseManualEntity <TKey>)x).Title.ToLower().Contains(q)); } if (filters.Count > 0) { pagination = await _repository.GetAsync(start, count, sortings, filters?.ToArray()); } else { pagination = await _repository.GetAsync(start, count, sortings); } var result = GetParsedPaginationResult(pagination.Entities, modelResponseType, pagination.Total, pagination.Start, pagination.Count, pagination.EntitySortings); return(result); }
protected PaginationResponseApiModel <IBaseApiModel <TKey>, TSorting> GetParsedPaginationResult(IEnumerable <TEntity> entities, TypeModelResponseEnum modelResponseType, int total, int start, int count, List <TSorting> sortings) { dynamic models; switch (modelResponseType) { case TypeModelResponseEnum.GetFullApiModel: models = _dataMapper.ParseCollection <TEntity, TModelGetFull>(entities); break; case TypeModelResponseEnum.GetMinApiModel: models = _dataMapper.ParseCollection <TEntity, TModelGetMin>(entities); break; default: models = _dataMapper.ParseCollection <TEntity, TModelGetFull>(entities); break; } var result = new PaginationResponseApiModel <IBaseApiModel <TKey>, TSorting>() { Total = total, Start = start, Count = count, EntitySortings = sortings, Models = models, }; return(result); }