示例#1
0
 public async Task<User> Post(User user)
 {
     using (var dbContext = new Context.ToDoContext())
     {
         user.UserId = Guid.NewGuid();
         user.Active = true;
         user.CreatedAt = DateTime.Now;
         user.UpDatedAt = DateTime.Now;
         dbContext.User.Add(user);
         await dbContext.SaveChangesAsync();
         return await Task.Run(() => user);
     }
 }
示例#2
0
 public async Task<User> Put(Guid userId, User user)
 {
     using (var dbContext = new Context.ToDoContext())
     {
         var userModel = await dbContext.User.FirstOrDefaultAsync(n => n.UserId.Equals(userId));
         userModel.Name = user.Name;
         userModel.Email = user.Email;
         userModel.UpDatedAt = DateTime.Now;
         await dbContext.SaveChangesAsync();
         user.UserId = userModel.UserId;
         return await Task.Run(() => user);
     }
 }
示例#3
0
 public async Task<User> Get(Guid userId)
 {
     using (var dbContext = new Context.ToDoContext())
     {
         var user = await dbContext.User.FirstOrDefaultAsync(n => n.UserId.Equals(userId) && n.Active) ?? new User();
         var userReturn = new User
         {
             UserId = user.UserId,
             Name = user.Name,
             Email = user.Email,
         };
         return await Task.Run(() => userReturn);
     }
 }