Пример #1
0
        /// <summary>
        /// Method to get all todoitems based on search criteria and pagesize
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="searchString"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task <List <ToDoItemExt> > SearchToDoItems(int userId, string searchString, int pageNumber, int pageSize)
        {
            using (var context = new ToDoServiceDBContext())
            {
                IQueryable <ToDoItemExt> items = (from item in context.ToDoItems
                                                  join label in context.Labels
                                                  on item.LabelId equals label.Id
                                                  where item.UserId == userId
                                                  select new ToDoItemExt
                {
                    Id = item.Id,
                    Name = item.Name,
                    Label = label.Name
                });

                if (!string.IsNullOrEmpty(searchString))
                {
                    return(await items.Where(s => s.Name.ToLower().Contains(searchString.ToLower())).DoPaging(pageNumber, pageSize).ToListAsync());
                }
                else
                {
                    return(await items.DoPaging(pageNumber, pageSize).ToListAsync());
                }
            }
        }
Пример #2
0
        public async Task <BaseToDoList> GetToDoListById(int itemId)
        {
            using (var context = new ToDoServiceDBContext())
            {
                BaseToDoList baseItem = (from item in context.ToDoLists
                                         join label in context.Labels
                                         on item.LabelId equals label.Id
                                         where item.Id == itemId
                                         select new BaseToDoList
                {
                    Id = item.Id,
                    Name = item.Name,
                }).FirstOrDefault();

                if (baseItem != null)
                {
                    baseItem.TodoItems = new List <BaseToDoItem>();
                    var db_item = await(from to_do_item in context.ToDoItems
                                        join label in context.Labels
                                        on to_do_item.LabelId equals label.Id
                                        where to_do_item.ToDoListId != null && to_do_item.ToDoListId.Value == baseItem.Id
                                        select new BaseToDoItem
                    {
                        Id   = to_do_item.Id,
                        Name = to_do_item.Name,
                    }).ToListAsync();

                    baseItem.TodoItems.AddRange(db_item);
                }
                return(baseItem);
            }
        }
Пример #3
0
 /// <summary>
 /// Method to register new user
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public async Task <int> RegisterUser(User user)
 {
     using (var context = new ToDoServiceDBContext())
     {
         context.Users.Add(user);
         return(await context.SaveChangesAsync());
     }
 }
Пример #4
0
 /// <summary>
 /// Method to add label
 /// </summary>
 /// <param name="label"></param>
 /// <returns></returns>
 public async Task <int> AddLabel(Domain.Models.Label label)
 {
     using (var context = new ToDoServiceDBContext())
     {
         context.Labels.Add(label);
         return(await context.SaveChangesAsync());
     }
 }
Пример #5
0
 /// <summary>
 /// Method to update todoitem
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public async Task <int> UpdateToDoItem(ToDoItem item)
 {
     using (var context = new ToDoServiceDBContext())
     {
         context.ToDoItems.Attach(item).Property(x => x.CreatedDate).IsModified = false;
         context.ToDoItems.Update(item);
         return(await context.SaveChangesAsync());
     }
 }
Пример #6
0
        /// <summary>
        /// Method to authenticate user
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <User> AuthenticateUser(string userName, string password)
        {
            using (var context = new ToDoServiceDBContext())
            {
                var user = await context.Users.FirstOrDefaultAsync(d => d.Name == userName && d.Password == password);

                return(user);
            }
        }
Пример #7
0
        /// <summary>
        /// Method to get colllection of labels
        /// </summary>
        /// <returns></returns>
        public async Task <List <Label> > GetLabels()
        {
            using (var context = new ToDoServiceDBContext())
            {
                var labels = await context.Labels.ToListAsync();

                return(labels);
            }
        }
Пример #8
0
        /// <summary>
        /// Method to get label by id
        /// </summary>
        /// <param name="labelId"></param>
        /// <returns></returns>
        public async Task <Label> GetLabelById(int labelId)
        {
            using (var context = new ToDoServiceDBContext())
            {
                var medicine = await context.Labels.FirstOrDefaultAsync(p => p.Id == labelId);

                return(medicine);
            }
        }
Пример #9
0
        /// <summary>
        /// Method to get todoitem by id
        /// </summary>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public async Task <BaseToDoItem> GetToDoItem(int itemId)
        {
            using (var context = new ToDoServiceDBContext())
            {
                var item = await context.ToDoItems.FindAsync(itemId);

                return(item);
            }
        }
Пример #10
0
        /// <summary>
        /// Method to delete label by id.
        /// </summary>
        /// <param name="labelId"></param>
        /// <returns></returns>
        public async Task <int> DeleteLabelById(int labelId)
        {
            using (var context = new ToDoServiceDBContext())
            {
                var id = await context.Labels.FindAsync(labelId);

                context.Labels.Remove(id);
                return(await context.SaveChangesAsync());
            }
        }
Пример #11
0
        /// <summary>
        /// Method to add new todoitem
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public async Task <int> AddToDoItem(ToDoItem item)
        {
            using (var context = new ToDoServiceDBContext())
            {
                context.ToDoItems.Add(item);
                int result = await context.SaveChangesAsync();

                return(result);
            }
        }
Пример #12
0
        /// <summary>
        /// Method to delete todoitem by id
        /// </summary>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public async Task <int> DeleteToDoItem(int itemId)
        {
            using (var context = new ToDoServiceDBContext())
            {
                var item = await context.ToDoItems.FindAsync(itemId);

                context.ToDoItems.Remove(item);
                return(await context.SaveChangesAsync());
            }
        }
Пример #13
0
        /// <summary>
        /// Method to add new todolist
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public async Task <int> AddToDoList(ToDoList item)
        {
            int result = 0;

            using (var context = new ToDoServiceDBContext())
            {
                context.ToDoLists.Add(item);
                result = await context.SaveChangesAsync();
            }
            return(result);
        }
Пример #14
0
        /// <summary>
        /// Method to get collection of todolist based on search criteria and pagesize
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="searchString"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task <List <ToDoListExt> > SearchToDoList(int userId, string searchString, int pageNumber, int pageSize)
        {
            List <ToDoListExt> toDoLists = null;

            using (var context = new ToDoServiceDBContext())
            {
                IQueryable <ToDoListExt> items = (from item in context.ToDoLists
                                                  join label in context.Labels
                                                  on item.LabelId equals label.Id
                                                  where item.UserId == userId
                                                  select new ToDoListExt
                {
                    Id = item.Id,
                    Name = item.Name,
                    Label = label.Name
                });

                if (!string.IsNullOrEmpty(searchString))
                {
                    toDoLists = await items.Where(s => s.Name.ToLower().Contains(searchString.ToLower())).DoPaging(pageNumber, pageSize).ToListAsync();
                }
                else
                {
                    toDoLists = await items.DoPaging(pageNumber, pageSize).ToListAsync();
                }


                if (toDoLists != null && toDoLists.Count > 0)
                {
                    foreach (var item in toDoLists)
                    {
                        item.ToDoItems = new List <ToDoItemExt>();
                        var db_item = await(from to_do_item in context.ToDoItems
                                            join label in context.Labels
                                            on to_do_item.LabelId equals label.Id
                                            where to_do_item.ToDoListId != null && to_do_item.ToDoListId.Value == item.Id
                                            select new ToDoItemExt
                        {
                            Id    = to_do_item.Id,
                            Name  = to_do_item.Name,
                            Label = label.Name
                        }).ToListAsync();

                        item.ToDoItems.AddRange(db_item);
                    }
                }
                return(toDoLists);
            }
        }
Пример #15
0
 /// <summary>
 /// Method to assign label to todoitem
 /// </summary>
 /// <param name="labelId"></param>
 /// <param name="itemId"></param>
 /// <returns></returns>
 public async Task <int> AssignLabelToItem(int labelId, int[] itemId)
 {
     using (var context = new ToDoServiceDBContext())
     {
         var items = context.ToDoItems;
         foreach (BaseToDoItem item in items)
         {
             if (itemId.Contains(item.Id))
             {
                 item.LabelId = labelId;
             }
         }
         return(await context.SaveChangesAsync());
     }
 }
Пример #16
0
 /// <summary>
 /// Method to assign label to todolist
 /// </summary>
 /// <param name="labelId"></param>
 /// <param name="listId"></param>
 /// <returns></returns>
 public async Task <int> AssignLabelToList(int labelId, int[] listId)
 {
     using (var context = new ToDoServiceDBContext())
     {
         var items = context.ToDoLists;
         foreach (ToDoList list in items)
         {
             if (listId.Contains(list.Id))
             {
                 list.LabelId = labelId;
             }
         }
         return(await context.SaveChangesAsync());
     }
 }
Пример #17
0
 /// <summary>
 /// Method to get all todoitems by user id.
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public async Task <List <ToDoItemExt> > GetToDoItems(int userId)
 {
     using (var context = new ToDoServiceDBContext())
     {
         List <ToDoItemExt> items = await(from item in context.ToDoItems
                                          join label in context.Labels
                                          on item.LabelId equals label.Id
                                          where item.UserId == userId
                                          select new ToDoItemExt
         {
             Id    = item.Id,
             Name  = item.Name,
             Label = label.Name
         }).ToListAsync();
         return(items);
     }
 }
Пример #18
0
        /// <summary>
        /// Method to get collection for todolist by user id
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <List <ToDoListExt> > GetToDoList(int userId)
        {
            using (var context = new ToDoServiceDBContext())
            {
                List <ToDoListExt> items = await(from item in context.ToDoLists
                                                 join label in context.Labels
                                                 on item.LabelId equals label.Id
                                                 where item.UserId == userId
                                                 select new ToDoListExt
                {
                    Id    = item.Id,
                    Name  = item.Name,
                    Label = label.Name
                }).ToListAsync();

                if (items != null && items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        item.ToDoItems = new List <ToDoItemExt>();
                        var db_item = await(from to_do_item in context.ToDoItems
                                            join label in context.Labels
                                            on to_do_item.LabelId equals label.Id
                                            where to_do_item.ToDoListId != null && to_do_item.ToDoListId.Value == item.Id
                                            select new ToDoItemExt
                        {
                            Id    = to_do_item.Id,
                            Name  = to_do_item.Name,
                            Label = label.Name
                        }).ToListAsync();

                        item.ToDoItems.AddRange(db_item);
                    }
                }
                return(items);
            }
        }