public async Task Delete(long id) { var entityToDelete = Include().FirstOrDefault(c => c.Id == id); _dbSet.Remove(entityToDelete); await _context.SaveChangesAsync(); }
public async Task <bool> DeleteAsync(Guid Id) { try { var result = await _dataSet.SingleOrDefaultAsync(c => c.Id.Equals(Id)); if (result == null) { return(false); } _dataSet.Remove(result); await _context.SaveChangesAsync(); return(true); } catch (Exception ex) { throw ex; } }
public async Task <SystemResponse> CreateUserAsync(UserRegister user) { var newUser = new User { Civility = user.Civility, FirstName = user.FirstName, LastName = user.LastName }; _context.Users.Add(newUser); await _context.SaveChangesAsync(); var userId = newUser.Id; var userCred = new UserCredentials { UserId = userId, Username = user.Username, Password = user.PassWord, IsAdmin = false }; _context.UserCredentials.Add(userCred); var canDelete = userCred.IsAdmin; var userDefaultAccessRight = new UserAccessRight { UserId = userId, Read = true, Write = true, Delete = canDelete }; _context.UserAccessRights.Add(userDefaultAccessRight); await _context.SaveChangesAsync(); return(SystemResponse.Success); }
public async Task <int> CreateAsync(int userId, string title, string content, DateTime creationDate, byte[] picture = null) { var userAccessRight = await _context.UserAccessRights.FirstOrDefaultAsync(u => u.UserId == userId); if (!userAccessRight.Write) { return(-1); } var newArticle = new Article { Title = title, Content = content, Picture = picture, UserId = userId, CreationDate = creationDate }; _context.Articles.Add(newArticle); await _context.SaveChangesAsync(); return(newArticle.Id); }
public virtual async Task Delete(T entity) { _entity.Remove(entity); await context.SaveChangesAsync(); }
/// <summary> /// Método de criação de endereço. /// </summary> /// <param name="person">Endereço a ser criado.</param> /// <returns></returns> public async Task Create(Address person) { await _context.AddAsync(person); await _context.SaveChangesAsync(); }
public async Task Update(Account account) { _context.Accounts.Update(account); await _context.SaveChangesAsync(); }
public async Task <int> CommitAsync() { return(await _db.SaveChangesAsync()); }