Beispiel #1
0
        public async Task <IActionResult> Delete(string problemName)
        {
            await _unitOfWork.ProblemRepository.DeleteProblemAsync(AppTypeName, problemName);

            await _unitOfWork.SaveAsync();

            return(Ok());
        }
Beispiel #2
0
        public async Task <OperationDetails> Create(UserDTO userDto)
        {
            User user = await _db.UserManager.FindByEmailAsync(userDto.Email);

            if (user == null)
            {
                user = new User {
                    Email = userDto.Email, UserName = userDto.Email
                };
                var result = await _db.UserManager.CreateAsync(user, userDto.Password);

                if (result.Errors.Count() > 0)
                {
                    return(new OperationDetails(false, result.Errors.FirstOrDefault(), ""));
                }
                // добавляем роль
                await _db.UserManager.AddToRoleAsync(user.Id, userDto.Role);

                // создаем профиль клиента
                userDto.Id = user.Id;
                var userProfile = new UserProfile {
                    Id        = user.Id,
                    FirstName = userDto.FirstName,
                    LastName  = userDto.LastName,
                    Country   = userDto.Country,
                    City      = userDto.City
                };
                _db.Repository <UserProfile>().Create(userProfile);

                await _db.SaveAsync();

                return(new OperationDetails(true, "Регистрация успешно пройдена", ""));
            }
            else
            {
                return(new OperationDetails(false, "Пользователь с таким логином уже существует", "Email"));
            }
        }