Пример #1
0
        public async Task <IActionResult> PutDaliyLog(DaliyLog daliyLog)
        {
            //if (id != daliyLog.Id)
            //{
            //    return BadRequest();
            //}
            if (daliyLog.Id != null && DaliyLogExists(daliyLog.Id))
            {
                _context.Entry(daliyLog).State = EntityState.Modified;
            }
            else
            {
                return(NotFound());
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DaliyLogExists(daliyLog.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <ResponseDto> CreateUserAsync(UserDto user)
        {
            try
            {
                var createUser = _mapper.Map <UserEntity>(user);
                createUser.Password = _coreRepository.GenerateHashedPassword(createUser.Password);
                _context.Users.Add(createUser);
                await _context.SaveChangesAsync();

                UserDto savedUser = _mapper.Map <UserDto>(createUser);
                return(CreateToken(savedUser));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
 public void Save()
 {
     _context.SaveChangesAsync();
 }
Пример #5
0
 public async Task SaveChanges() => await usersDBContext.SaveChangesAsync();