public async Task <ProfileDto> CreateProfile(ProfileRequestDto createProfile)
        {
            var checkForEmployee = _stationeryContext.Users.Where(e => e.CorporateEmail == createProfile.CorporateEmail).FirstOrDefault();

            if (checkForEmployee != null)
            {
                throw new AppException("User exists");
            }

            var newUser = new User
            {
                //UserId = Guid.NewGuid(),
                FirstName      = createProfile.FirstName,
                LastName       = createProfile.LastName,
                CorporateEmail = createProfile.CorporateEmail,
                //JobPosition = createProfile.JobPosition,
                IsActive = 1,
                UnitId   = _stationeryContext.Units.Where(u => u.UnitName == createProfile.UnitName).Select(i => i.UnitId).FirstOrDefault()
            };

            await _stationeryContext.AddAsync(newUser);

            await _stationeryContext.SaveChangesAsync();

            return(GetProfile(newUser.UserId));
        }
Beispiel #2
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                SprUser user = await db.SprUser.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    db.SprUser.Add(new SprUser {
                        Email = model.Email, Password = model.Password
                    });
                    await db.SaveChangesAsync();

                    await Authenticate(user); // аутентификация

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }

            return(View(model));
        }