Beispiel #1
0
 public async Task<User> Authenticate(string email, string password)
 {
     using (var dbContext = new Context.ToDoContext())
     {
         var user = await dbContext.User.FirstOrDefaultAsync(n => n.Email.Equals(email) && n.Password.Equals(password) && n.Active);
         return await Task.Run(() => user);
     }
 }
Beispiel #2
0
        public async Task <User> Authenticate(string email, string password)
        {
            using (var dbContext = new Context.ToDoContext())
            {
                var user = await dbContext.User.FirstOrDefaultAsync(n => n.Email.Equals(email) && n.Password.Equals(password) && n.Active);

                return(await Task.Run(() => user));
            }
        }
Beispiel #3
0
        public async Task Delete(Guid userId)
        {
            using (var dbContext = new Context.ToDoContext())
            {
                var userModel = await dbContext.User.FirstOrDefaultAsync(n => n.UserId.Equals(userId));

                userModel.Active = false;
                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #4
0
        public async Task Delete(Guid todoId)
        {
            using (var dbContext = new Context.ToDoContext())
            {
                var todo = await dbContext.ToDo.FirstOrDefaultAsync(n => n.ToDoId.Equals(todoId));

                todo.Active    = false;
                todo.UpDatedAt = DateTime.Now;
                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #5
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);
     }
 }
Beispiel #6
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);
     }
 }
Beispiel #7
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);
     }
 }
Beispiel #8
0
 public async Task<ToDo> Get(Guid todoId, Guid userId)
 {
     using (var dbContext = new Context.ToDoContext())
     {
         var todo = await dbContext.ToDo.FirstOrDefaultAsync(n => n.ToDoId.Equals(todoId) && !n.Completed && n.UserId.Equals(userId) && n.Active) ?? new ToDo();
         var todoReturn = new ToDo
         {
             ToDoId = todo.ToDoId,
             Description = todo.Description,
             Completed = todo.Completed,
             UserId = todo.UserId
         };
         return await Task.Run(() => todoReturn);
     }
 }
Beispiel #9
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));
            }
        }
Beispiel #10
0
        public async Task <User> Post(User user)
        {
            using (var dbContext = new Context.ToDoContext())
            {
                user.UserId    = Guid.NewGuid();
                user.Password  = user.Password;
                user.Active    = true;
                user.CreatedAt = DateTime.Now;
                user.UpDatedAt = DateTime.Now;
                dbContext.User.Add(user);
                await dbContext.SaveChangesAsync();

                return(await Task.Run(() => user));
            }
        }
Beispiel #11
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));
            }
        }
Beispiel #12
0
        public async Task <ToDo> Get(Guid todoId, Guid userId)
        {
            using (var dbContext = new Context.ToDoContext())
            {
                var todo = await dbContext.ToDo.FirstOrDefaultAsync(n => n.ToDoId.Equals(todoId) && !n.Completed && n.UserId.Equals(userId) && n.Active) ?? new ToDo();

                var todoReturn = new ToDo
                {
                    ToDoId      = todo.ToDoId,
                    Description = todo.Description,
                    Completed   = todo.Completed,
                    UserId      = todo.UserId
                };
                return(await Task.Run(() => todoReturn));
            }
        }
Beispiel #13
0
        public async Task <ToDo> Put(Guid todoId, ToDo todo)
        {
            using (var dbContext = new Context.ToDoContext())
            {
                var todoModel = await dbContext.ToDo.FirstOrDefaultAsync(n => n.ToDoId.Equals(todoId));

                todoModel.Description = todo.Description;
                todoModel.Completed   = todo.Completed;
                todoModel.UpDatedAt   = DateTime.Now;
                await dbContext.SaveChangesAsync();

                todo.Completed = todoModel.Completed;
                todo.ToDoId    = todoModel.ToDoId;
                todo.UserId    = todoModel.UserId;
                return(await Task.Run(() => todo));
            }
        }
Beispiel #14
0
 public async Task<ICollection<User>> Get()
 {
     var usersReturn = new List<User>();
     using (var dbContext = new Context.ToDoContext())
     {
         var users = await dbContext.User.Where(n => n.Active).ToListAsync();
         foreach (var user in users)
         {
             usersReturn.Add(new User
             {
                 UserId = user.UserId,
                 Name = user.Name,
                 Email = user.Email,
             });
         }
         return await Task.Run(() => usersReturn);
     }
 }
Beispiel #15
0
        public async Task<ToDo> Post(Guid userId, ToDo todo)
        {
            using (var dbContext = new Context.ToDoContext())
            {
                dbContext.ToDo.Add(new Entities.ToDo
                {
                    ToDoId = todo.ToDoId = Guid.NewGuid(),
                    Description = todo.Description,
                    Completed = false,
                    Active = true,
                    UserId = todo.UserId = userId,
                    CreatedAt = DateTime.Now,
                    UpDatedAt = DateTime.Now
                });

                await dbContext.SaveChangesAsync();
                return await Task.Run(() => todo);
            }
        }
Beispiel #16
0
 public async Task<ICollection<ToDo>> Get(Guid userId)
 {
     var doingsReturn = new List<ToDo>();
     using (var dbContext = new Context.ToDoContext())
     {
         var doings = await dbContext.ToDo.Include(n => n.User).Where(n => n.User.UserId.Equals(userId) && !n.Completed && n.Active).ToListAsync();
         foreach (var todo in doings)
         {
             doingsReturn.Add(new ToDo
             {
                 ToDoId = todo.ToDoId,
                 Description = todo.Description,
                 Completed = todo.Completed,
                 UserId = todo.UserId
             });
         }
         return await Task.Run(() => doingsReturn);
     }
 }
Beispiel #17
0
        public async Task <ICollection <User> > Get()
        {
            var usersReturn = new List <User>();

            using (var dbContext = new Context.ToDoContext())
            {
                var users = await dbContext.User.Where(n => n.Active).ToListAsync();

                foreach (var user in users)
                {
                    usersReturn.Add(new User
                    {
                        UserId = user.UserId,
                        Name   = user.Name,
                        Email  = user.Email,
                    });
                }
                return(await Task.Run(() => usersReturn));
            }
        }
Beispiel #18
0
        public async Task <ToDo> Post(Guid userId, ToDo todo)
        {
            using (var dbContext = new Context.ToDoContext())
            {
                dbContext.ToDo.Add(new Entities.ToDo
                {
                    ToDoId      = todo.ToDoId = Guid.NewGuid(),
                    Description = todo.Description,
                    Completed   = false,
                    Active      = true,
                    UserId      = todo.UserId = userId,
                    CreatedAt   = DateTime.Now,
                    UpDatedAt   = DateTime.Now
                });

                await dbContext.SaveChangesAsync();

                return(await Task.Run(() => todo));
            }
        }
Beispiel #19
0
        public async Task <ICollection <ToDo> > Get(Guid userId)
        {
            var doingsReturn = new List <ToDo>();

            using (var dbContext = new Context.ToDoContext())
            {
                var doings = await dbContext.ToDo.Include(n => n.User).Where(n => n.User.UserId.Equals(userId) && !n.Completed && n.Active).ToListAsync();

                foreach (var todo in doings)
                {
                    doingsReturn.Add(new ToDo
                    {
                        ToDoId      = todo.ToDoId,
                        Description = todo.Description,
                        Completed   = todo.Completed,
                        UserId      = todo.UserId
                    });
                }
                return(await Task.Run(() => doingsReturn));
            }
        }
Beispiel #20
0
 public async Task Delete(Guid userId)
 {
     using (var dbContext = new Context.ToDoContext())
     {
         var userModel = await dbContext.User.FirstOrDefaultAsync(n => n.UserId.Equals(userId));
         userModel.Active = false;
         await dbContext.SaveChangesAsync();
     }
 }
Beispiel #21
0
 public async Task<ToDo> Put(Guid todoId, ToDo todo)
 {
     using (var dbContext = new Context.ToDoContext())
     {
         var todoModel = await dbContext.ToDo.FirstOrDefaultAsync(n => n.ToDoId.Equals(todoId));
         todoModel.Description = todo.Description;
         todoModel.Completed = todo.Completed;
         todoModel.UpDatedAt = DateTime.Now;
         await dbContext.SaveChangesAsync();
         todo.Completed = todoModel.Completed;
         todo.ToDoId = todoModel.ToDoId;
         todo.UserId = todoModel.UserId;
         return await Task.Run(() => todo);
     }
 }
Beispiel #22
0
 public async Task Delete(Guid todoId)
 {
     using (var dbContext = new Context.ToDoContext())
     {
         var todo = await dbContext.ToDo.FirstOrDefaultAsync(n => n.ToDoId.Equals(todoId));
         todo.Active = false;
         todo.UpDatedAt = DateTime.Now;
         await dbContext.SaveChangesAsync();
     }
 }