public AppUser SaveOrUpdate(UserSectorsModel userSectorsModel)
        {
            using (var tran = UnitOfWork.Context.Database.BeginTransaction())
            {
                try
                {
                    int id;
                    if (userSectorsModel.IsNew)
                    {
                        var user = _appUserRepository.Add(new AppUser()
                        {
                            Name = userSectorsModel.Name, TermsIsAccepted = userSectorsModel.TermsIsAccepted
                        });

                        foreach (var sector in userSectorsModel.Sectors)
                        {
                            _userSectorsRepository.Add(new UsersSector()
                            {
                                SectorId = sector.Id,
                                UserId   = user.Id
                            });
                        }

                        id = user.Id;
                    }
                    else
                    {
                        _appUserRepository.Update(new AppUser()
                        {
                            Id              = userSectorsModel.Id,
                            Name            = userSectorsModel.Name,
                            TermsIsAccepted = true,
                            UsersSectors    = null
                        });

                        _userSectorsRepository.DeleteWhere(x => x.UserId == userSectorsModel.Id);

                        foreach (var sector in userSectorsModel.Sectors)
                        {
                            _userSectorsRepository.Add(new UsersSector()
                            {
                                SectorId = sector.Id,
                                UserId   = userSectorsModel.Id
                            });
                        }

                        id = userSectorsModel.Id;
                    }

                    tran.Commit();
                    var result = _appUserRepository.Get(id);
                    return(result);
                }
                catch (Exception)
                {
                    tran.Rollback();
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        public void Add(UserDTO model)
        {
            AppUser appUser = new AppUser();

            appUser.InjectFrom(model);
            userRepository.Add(appUser);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddUser([FromBody] AppUserSaveResource appUserResource)
        {
            if (!_auth.IsSuperAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = _mapper.Map <MdaAppUser>(appUserResource);

            user.CreatedBy = User.Identity.Name.Replace("\\\\", "\\");
            _repo.Add(user);
            if (await _repo.SaveAll())
            {
                // var userToReturn = _mapper.Map<AppUserForReturnResource>(user);
                // return CreatedAtRoute("GetUser", new { id = user.Id}, userToReturn);
                // return NoContent();
                return(Ok(user));
            }

            return(BadRequest("Could not add user"));
        }
Exemplo n.º 4
0
        public void Insert(AppUserViewModelRequest viewModel)
        {
            var model = _mapper.Map <AppUser>(viewModel);

            _appUserRepository.Add(model);

            _unitOfWork.Commit();
        }
        public async Task <int> Register(string username, string password)
        {
            var result =
                _appUserRepository.Add(new AppUser
            {
                PasswordHash = CryptHelper.SHA1(password),
                Name         = username
            });
            await _unitOfWork.CommitAsync();

            return(result.Id);
        }
        public async Task GetProfile()
        {
            EnsureInternetAvailable();
            await EnsureSessionIsValid();

            try
            {
                var accessToken = await GetAccessToken();

                var contract = await _authWebService.GetProfile(accessToken);

                var dataObject = Mapper.Map <AppUserDataObject>(contract);
                _appUserRepository.Clear();
                _appUserRepository.Add(dataObject);
            }
            catch (ApiException ex)
            {
                throw new ServerErrorException(ex.Message);
            }
        }
Exemplo n.º 7
0
        public Task Handle(RegisterAppUserCommand message, CancellationToken cancellationToken)
        {
            var appUser = new AppUser(message.Id, message.Email);

            if (!appUser.IsValid())
            {
                NotificarValidacoesErro(appUser.ValidationResult);
                return(Task.CompletedTask);
            }

            var appUserCore = _appUserRepository.GetById(appUser.Id);

            if (appUserCore != null && appUserCore.Id == appUser.Id)
            {
                _mediator.PublishEvent(new DomainNotification(message.MessageType, "An user with this email already exists."));
                return(Task.CompletedTask);
            }

            _appUserRepository.Add(appUser);
            _mediator.PublishEvent(new AppUserRegisteredEvent(appUser.Id, appUser.Email));

            return(Task.CompletedTask);
        }
Exemplo n.º 8
0
 public AppUser Add(AppUser newAppUser)
 {
     return(_appUserRepository.Add(newAppUser));
 }
Exemplo n.º 9
0
        public IActionResult Create([FromBody] AppUser newentry)
        {
            var result = _repository.Add(newentry);

            return(Helper.CheckResult(result));
        }
Exemplo n.º 10
0
 public void Create(AppUser appUser)
 {
     appUserRepository.Add(appUser);
 }
Exemplo n.º 11
0
 public void Add(AppUser appUser)
 {
     _appUserRepository.Add(appUser);
 }