public BL.Domain.User.User UpdateUser(BL.Domain.User.User user) { var entryToUpdate = ReadUser(user.Id); if (entryToUpdate == null) { throw new ArgumentException("User to update not found."); } _ctx.Entry(entryToUpdate).CurrentValues.SetValues(user); _ctx.SaveChanges(); return(ReadUser(user.Id)); }
public BL.Domain.User.User CreateUser(BL.Domain.User.User user) { if (ReadUser(user.Id) != null) { throw new ArgumentException("User already in database."); } try { _ctx.Users.Add(user); _ctx.SaveChanges(); return(user); } catch (DbUpdateException exception) { var msg = exception.InnerException == null ? "Invalid object." : exception.InnerException.Message; throw new ArgumentException(msg); } }