Exemplo n.º 1
0
        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));
        }