Beispiel #1
0
        public virtual async Task <T> UpdateAsync(T entity)
        {
            T dbEntity = await _dbSet.FindAsync(entity.Id);

            if (dbEntity == null)
            {
                return(null);
            }
            _dbContext.Entry(dbEntity).CurrentValues.SetValues(entity);
            await _dbContext.SaveChangesAsync();

            return(dbEntity);
        }
Beispiel #2
0
        public async Task <UserDTO> AddOrUpdateAsync(UserDTO user)
        {
            SyllabusManagerUser dbUser = await _dbSet.FindAsync(user.Id);

            if (dbUser == null)
            {
                return(await AddAsync(user));
            }
            List <string> roles = (await _userManager.GetRolesAsync(dbUser)).ToList();
            await _userManager.RemoveFromRolesAsync(dbUser, roles);

            await _userManager.AddToRolesAsync(dbUser, user.Roles);

            _dbContext.Entry(dbUser).CurrentValues.SetValues(user);
            dbUser.NormalizedEmail = user.Email.ToUpper();

            await _dbContext.SaveChangesAsync();

            roles = (await _userManager.GetRolesAsync(dbUser)).ToList();
            return(dbUser.MakeDto(roles));
        }