Exemplo n.º 1
0
        public void Update(UpdateUserData model, IValidationErrors errors)
        {
            if (!model.Validate(errors))
            {
                return;
            }

            var user = UnitOfWork.Users.Include(x => x.UserModules).FirstOrDefault(x => x.Id == model.UserId);

            if (user == null)
            {
                throw new Exception("User not found");
            }

            model.MapTo(user);
            foreach (var userModule in user.UserModules)
            {
                var modelUserModule = model.Modules.FirstOrDefault(x => x.Id == userModule.ModuleId);
                if (modelUserModule == null)
                {
                    continue;
                }
                if (modelUserModule.Permission == userModule.Permission)
                {
                    continue;
                }

                modelUserModule.MapTo(userModule);
            }

            UnitOfWork.SaveChanges();
        }
        public async Task <UserDto> UpdateUser(long userId, UpdateUserData userData)
        {
            await using var tmp = await connectionController.OpenConnectionAsync();

            var user = await repo.GetUser(userId);

            if (user.Email != userData.Email)
            {
                user.EmailVerified = false;
            }

            userData.MapTo(user, mapper);

            user = await repo.UpdateUser(user);

            return(user.ToDto(mapper));
        }