public static async Task DeleteAsync(Guid id) { using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>()) { await repository.DeleteAsync(id).ConfigureAwait(false); } }
public static async Task <FilterEntityContainerWrapper <Models.Subject> > GetFiltered(int pageNumber = 0, StudentSubjectFilterModel model = null, IList <string> navigationProperties = null) { using (var subjectRepository = RepoUnitOfWork.CreateRepository <SubjectRepository>()) { if (model == null) { model = StudentSubjectFilterModel.Default(); } var entityContainerWraper = new FilterEntityContainerWrapper <Models.Subject>(); var entityContainers = new List <EntityContainer <Models.Subject> >(); var subjectQuery = subjectRepository.GetAllQuery(navigationProperties); var offeredPaginationData = ExtractTotalPagesAsync(subjectQuery, model); if (pageNumber > offeredPaginationData.TotalPages) { pageNumber = 0; } var offeredShiftsModel = await GetOrderShiftsByFilter(null, pageNumber, offeredPaginationData.TotalPages, model, navigationProperties).ConfigureAwait(false); entityContainers.Add(offeredShiftsModel); entityContainerWraper.EntityContainers = entityContainers; entityContainerWraper.TotalItems = offeredPaginationData.TotalEntryCount; return(entityContainerWraper); } }
private static async Task <EntityContainer <Models.Subject> > GetOrderShiftsByFilter(SubjectRepository subjectsRepository, int currentPageNumber, int numberOfPages, StudentSubjectFilterModel model, IList <string> navigationProperties = null) { if (subjectsRepository == null) { subjectsRepository = RepoUnitOfWork.CreateRepository <SubjectRepository>(); } using (var subjectQuery = GetFilterQuery(subjectsRepository, model, navigationProperties)) { if (!subjectQuery.IsValid) { return(new EntityContainer <Models.Subject> { CurrentPage = 0, TotalPages = 0, Data = new List <Models.Subject>() }); } var orderedQuery = subjectQuery.OrderBy(subject => subject.SubjectName).Paginate(currentPageNumber, PaginationConstants.REGISTRATION_PER_PAGE); var subjectList = await orderedQuery.ExecuteAsync().ConfigureAwait(false); if (subjectList == null) { subjectList = new List <Models.Subject>(); } return(new EntityContainer <Models.Subject> { CurrentPage = currentPageNumber, TotalPages = numberOfPages, Data = subjectList.CopyTo <Models.Subject>().ToList() }); } }
public static void Delete(Guid id) { using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>()) { repository.Delete(id); } }
public static async Task <bool> IsUserIdAuthorizedAsync(string aspNetUserId, List <string> roleIdList) { if (string.IsNullOrWhiteSpace(aspNetUserId)) { return(false); } using (var aspNetUsersRepository = RepoUnitOfWork.CreateRepository <AspNetUserRepository>()) { var user = await aspNetUsersRepository.GetAsync(aspNetUserId, new[] { nameof(AspNetUser.AspNetRoles) }).ConfigureAwait(false); if (user == null) { return(false); } var isApproved = user.Status == (int)UserStatus.ACTIVE; if (!isApproved) { return(false); } if (user.AspNetRoles == null) { return(false); } //if at least one role is found return(roleIdList.Any(roleId => user.AspNetRoles.Any(role => role.Id == roleId))); } }
public static async Task <Response <AspNetUser> > CreateAspNetUserAsync(RepoUnitOfWork repoUnitOfWork, CreateUserModel model) { var response = ResponseFactory.Error <AspNetUser>(); if (repoUnitOfWork == null) { repoUnitOfWork = RepoUnitOfWork.New(); } var aspNetUserRepository = repoUnitOfWork.TrackingRepository <AspNetUserRepository>(); if (!await IsEmailNotUsedAsync(model.Email).ConfigureAwait(false)) { return(response); } var aspNetUser = new AspNetUser { Id = Guid.NewGuid().ToString(), UserName = model.Email, PasswordHash = model.PasswordHash, SecurityStamp = Guid.NewGuid().ToString("D"), }; var createdAspNetUser = await aspNetUserRepository.CreateAsync(aspNetUser, navigationProperties : new[] { nameof(AspNetRole) }).ConfigureAwait(false); if (createdAspNetUser == null) { return(response); } return(ResponseFactory.Success(createdAspNetUser)); }
public static IConfigurableQuery <TEntity, TModel> GetListQuery(Expression <Func <TEntity, bool> > where, IList <string> navigationProperties = null) { var repository = RepoUnitOfWork.CreateRepository <TRepo>(); var query = repository.GetListQuery(@where, navigationProperties); return(new ConfigurableQuery <TEntity, TModel>(repository.Context, query)); }
public async Task <float?> SumAsync(Expression <Func <TDataAccessModel, float?> > selector) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { return(await repository.SumAsync(selector).ConfigureAwait(false)); } }
public static Response UpdateExercises(CreateExerciseViewModel model) { if (model.Id == Guid.Empty) { return(null); } using (var unitOfWork = RepoUnitOfWork.New()) { var exerciseRepo = unitOfWork.TrackingRepository <ExerciseRepository>(); var exercises = exerciseRepo.Get(model.Id); if (exercises == null) { return(null); } exercises.MuscleGroupId = model.MuscleGroupId; exercises.PictureUrl = model.PictureUrl; exercises.Description = model.Description; exercises.VideoUrl = model.VideoUrl; exercises.Name = model.Name; var updatedExercise = exerciseRepo.Update(exercises); if (updatedExercise == null) { return(null); } unitOfWork.CommitTransaction(); return(ResponseFactory.SuccessResponse); } }
public static IEnumerable <TEntity> ExecuteStoredProcedureList(IStoreProcedure storedProcedure) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { return(repository.ExecuteStoredProcedureList <TEntity>(storedProcedure)); } }
public static async Task <UserViewModel> GetUserData(string aspNetUserId) { if (string.IsNullOrWhiteSpace(aspNetUserId) || aspNetUserId == Guid.Empty.ToString()) { return(null); } var userRepo = RepoUnitOfWork.CreateTrackingRepository <UserRepository>(); var user = await userRepo.GetSingleAsync(usr => usr.AspNetUserId == aspNetUserId, new[] { nameof(User.AspNetUser) }).ConfigureAwait(false); var model = new UserViewModel() { AspNetUserId = user.AspNetUserId, UserId = user.Id, ProfilePictureUrl = user.ProfilePictureUrl, BodyWeight = 0, CaloriesBurned = 0, GoalsAchived = 0, Achivements = 0, DailyGoal = 0, Email = user.AspNetUser.Email, FullName = user.FullName, BirthDay = user.BirthDay ?? user.BirthDay.Value, DailyMin = 0, WeeklyMin = 0, MonthlyMin = 0, }; return(model); }
public static async Task <bool> DeleteAsync(IList <TEntity> modelCollection) { using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>()) { return(await repository.DeleteAsync(modelCollection).ConfigureAwait(false)); } }
public static void ExecuteStoredProcedure(IStoreProcedure storedProcedure) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { repository.ExecuteStoredProcedure(storedProcedure); } }
public static IQueryable <TEntity> GetListQuery(Expression <Func <TEntity, bool> > where, IList <string> navigationProperties = null) { var repository = RepoUnitOfWork.CreateRepository <TRepo>(); var query = repository.GetListQuery(@where, navigationProperties); return(query); }
public async Task <int?> SumAsync(Expression <Func <TEntity, int?> > selector) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { return(await repository.SumAsync(selector).ConfigureAwait(false)); } }
public static IConfigurableQuery <TEntity> GetAllQuery(IList <string> navigationProperties = null) { var repository = RepoUnitOfWork.CreateRepository <TRepo>(); var query = repository.GetAllQuery(navigationProperties); return(new ConfigurableQuery <TEntity>(repository.Context, query)); }
public async Task <decimal?> MaxAsync(Expression <Func <TDataAccessModel, decimal?> > selector, Expression <Func <TDataAccessModel, bool> > where) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { return(await repository.MaxAsync(selector, @where).ConfigureAwait(false)); } }
public static int Count(Expression <Func <TEntity, bool> > where) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { return(repository.Count(@where)); } }
public async Task <float> SumAsync(Expression <Func <TEntity, float> > selector, Expression <Func <TEntity, bool> > where) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { return(await repository.SumAsync(selector, @where).ConfigureAwait(false)); } }
public static async Task <int> CountAsync(Expression <Func <TEntity, bool> > where) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { return(await repository.CountAsync(@where).ConfigureAwait(false)); } }
public static async Task <int> CountAsync() { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { return(await repository.CountAsync().ConfigureAwait(false)); } }
public static async Task <Response> Register(RegisterViewModel registerModel, string passwordHash) { using (var repoUnitOfWork = RepoUnitOfWork.New()) { var aspNetUser = new AspNetUser { Id = registerModel.Id.ToString(), Email = registerModel.Email, UserName = registerModel.Email, UserType = (int)registerModel.userType, Status = (int)UserStatus.ACTIVE, PhoneNumber = registerModel.PhoneNumber, CreatedAt = DateTime.UtcNow, PasswordHash = passwordHash, }; var aspNetUserRepo = repoUnitOfWork.TrackingRepository <AspNetUserRepository>(); var createdUser = await aspNetUserRepo.CreateAsync(aspNetUser).ConfigureAwait(false); if (createdUser != null) { repoUnitOfWork.CommitTransaction(); return(ResponseFactory.Success <AspNetUser>()); } repoUnitOfWork.RollbackTransaction(); return(ResponseFactory.Error <AspNetUser>()); } }
public static async Task <bool> DeleteAsync(TDataAccessModel model) { using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>()) { return(await repository.DeleteAsync(model).ConfigureAwait(false)); } }
public static TDataAccessModel GetEf(Guid id, IList <string> navigationProperties = null) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { var entities = repository.Get(id, navigationProperties); return(entities); } }
public static TEntity Update(TEntity model, bool refreshFromDb = false, IList <string> navigationProperties = null) { using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>()) { var entity = repository.Update(model, refreshFromDb, navigationProperties); return(entity); } }
public static IList <TEntity> GetListEF(Expression <Func <TEntity, bool> > where, IList <string> navigationProperties = null) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { var entities = repository.GetList(@where, navigationProperties); return(entities); } }
public static IList <TEntity> GetAll(IList <string> navigationProperties = null) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { var entities = repository.GetAll(navigationProperties); return(entities); } }
public static TDataAccessModel Update(TDataAccessModel entity, bool refreshFromDb = false, IList <string> navigationProperties = null) { using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>()) { entity = repository.Update(entity, refreshFromDb, navigationProperties); return(entity); } }
public static TDataAccessModel GetSingle(Expression <Func <TDataAccessModel, bool> > where, IList <string> navigationProperties = null) { using (var repository = RepoUnitOfWork.CreateRepository <TRepo>()) { var entities = repository.GetSingle(where, navigationProperties); return(entities); } }
public static void Delete(Guid id, TRepo repo = null) { if (repo == null) { repo = RepoUnitOfWork.CreateTrackingRepository <TRepo>(); } repo.Delete(id); }