Esempio n. 1
0
 public static async Task DeleteAsync(Guid id)
 {
     using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>())
     {
         await repository.DeleteAsync(id).ConfigureAwait(false);
     }
 }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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()
                });
            }
        }
Esempio n. 4
0
 public static void Delete(Guid id)
 {
     using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>())
     {
         repository.Delete(id);
     }
 }
Esempio n. 5
0
        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)));
            }
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
 public async Task <float?> SumAsync(Expression <Func <TDataAccessModel, float?> > selector)
 {
     using (var repository = RepoUnitOfWork.CreateRepository <TRepo>())
     {
         return(await repository.SumAsync(selector).ConfigureAwait(false));
     }
 }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
 public static IEnumerable <TEntity> ExecuteStoredProcedureList(IStoreProcedure storedProcedure)
 {
     using (var repository = RepoUnitOfWork.CreateRepository <TRepo>())
     {
         return(repository.ExecuteStoredProcedureList <TEntity>(storedProcedure));
     }
 }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
 public static async Task <bool> DeleteAsync(IList <TEntity> modelCollection)
 {
     using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>())
     {
         return(await repository.DeleteAsync(modelCollection).ConfigureAwait(false));
     }
 }
Esempio n. 13
0
 public static void ExecuteStoredProcedure(IStoreProcedure storedProcedure)
 {
     using (var repository = RepoUnitOfWork.CreateRepository <TRepo>())
     {
         repository.ExecuteStoredProcedure(storedProcedure);
     }
 }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
 public async Task <int?> SumAsync(Expression <Func <TEntity, int?> > selector)
 {
     using (var repository = RepoUnitOfWork.CreateRepository <TRepo>())
     {
         return(await repository.SumAsync(selector).ConfigureAwait(false));
     }
 }
Esempio n. 16
0
        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));
        }
Esempio n. 17
0
 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));
     }
 }
Esempio n. 18
0
 public static int Count(Expression <Func <TEntity, bool> > where)
 {
     using (var repository = RepoUnitOfWork.CreateRepository <TRepo>())
     {
         return(repository.Count(@where));
     }
 }
Esempio n. 19
0
 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));
     }
 }
Esempio n. 20
0
 public static async Task <int> CountAsync(Expression <Func <TEntity, bool> > where)
 {
     using (var repository = RepoUnitOfWork.CreateRepository <TRepo>())
     {
         return(await repository.CountAsync(@where).ConfigureAwait(false));
     }
 }
Esempio n. 21
0
 public static async Task <int> CountAsync()
 {
     using (var repository = RepoUnitOfWork.CreateRepository <TRepo>())
     {
         return(await repository.CountAsync().ConfigureAwait(false));
     }
 }
Esempio n. 22
0
        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>());
            }
        }
Esempio n. 23
0
 public static async Task <bool> DeleteAsync(TDataAccessModel model)
 {
     using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>())
     {
         return(await repository.DeleteAsync(model).ConfigureAwait(false));
     }
 }
Esempio n. 24
0
 public static TDataAccessModel GetEf(Guid id, IList <string> navigationProperties = null)
 {
     using (var repository = RepoUnitOfWork.CreateRepository <TRepo>())
     {
         var entities = repository.Get(id, navigationProperties);
         return(entities);
     }
 }
Esempio n. 25
0
 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);
     }
 }
Esempio n. 26
0
 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);
     }
 }
Esempio n. 27
0
 public static IList <TEntity> GetAll(IList <string> navigationProperties = null)
 {
     using (var repository = RepoUnitOfWork.CreateRepository <TRepo>())
     {
         var entities = repository.GetAll(navigationProperties);
         return(entities);
     }
 }
Esempio n. 28
0
 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);
     }
 }
Esempio n. 29
0
 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);
     }
 }
Esempio n. 30
0
 public static void Delete(Guid id, TRepo repo = null)
 {
     if (repo == null)
     {
         repo = RepoUnitOfWork.CreateTrackingRepository <TRepo>();
     }
     repo.Delete(id);
 }