Ejemplo n.º 1
0
        public async Task <ServerResult> CreateAsync(PersonDto model)
        {
            var newModel = _mapper.Map <Person>(model);

            _context.People.Add(newModel);
            await _context.SaveChangesAsync();

            return(ServerResult.Success());
        }
Ejemplo n.º 2
0
        public async Task <ServerResult> DeleteUserAsync(ApplicationUser user)
        {
            var result = await _userManager.DeleteAsync(user);

            return(result.Succeeded ? ServerResult.Success() : new ServerResult()
            {
                Succeeded = false,
                Errors = result.Errors.Select(e => e.Description).ToArray()
            });
        }
Ejemplo n.º 3
0
        public async Task <ServerResult> DeleteUserAsync(string userId)
        {
            var user = await _userManager.Users.SingleOrDefaultAsync(u => u.Id == userId);

            if (user != null)
            {
                return(await DeleteUserAsync(user));
            }

            return(ServerResult.Success());
        }
Ejemplo n.º 4
0
        public async Task <ServerResult> CreateUserAsync(UserDto model)
        {
            var user = new ApplicationUser
            {
                UserName  = model.UserName,
                Email     = model.Email,
                FirstName = model.FirstName,
                LastName  = model.LastName
            };

            var result = await _userManager.CreateAsync(user, model.Password);

            return(result.Succeeded ? ServerResult.Success() : new ServerResult()
            {
                Succeeded = false,
                Errors = result.Errors.Select(e => e.Description).ToArray()
            });
        }
Ejemplo n.º 5
0
        public async Task <ServerResult> UpdateUserAsync(UserDto model)
        {
            var user = await _userManager.Users.SingleOrDefaultAsync(u => u.UserName == model.UserName);

            if (user == null)
            {
                throw new EducaException("userName_not_found"
                                         , $"UserName: '******' was not found.");
            }

            _mapper.Map(model, user);

            var result = await _userManager.UpdateAsync(user);

            return(result.Succeeded ? ServerResult.Success() : new ServerResult()
            {
                Succeeded = false,
                Errors = result.Errors.Select(e => e.Description).ToArray()
            });
        }