Esempio n. 1
0
        void TasksTree_RemoteRename(object sender, RemoteEditEventArgs e)
        {
            try
            {
                int nodeId = int.Parse(e.NodeID);

                SimpleTasksDataContext ctx = this.DBContext;

                Category category = (from tl in ctx.Categories
                                     where tl.ID == nodeId
                                     select tl).First();

                IEnumerable <Category> query = from tl in ctx.Categories
                                               where (tl.IsFolder == category.IsFolder && tl.ParentID == category.ParentID && tl.ID != category.ID && tl.Name == e.Value <string>())
                                               select tl;

                if (query.Count() > 0)
                {
                    e.Accept         = false;
                    e.RefusalMessage = "Such {0} is existing in the parent folder".FormatWith(category.IsFolder ? "folder" : "category");
                    return;
                }

                category.Name = e.Value <string>();
                ctx.SubmitChanges();
                e.Accept = true;
            }
            catch (Exception exception)
            {
                e.Accept         = false;
                e.RefusalMessage = exception.Message;
            }
        }
Esempio n. 2
0
        void TasksTree_RemoteMove(object sender, RemoteMoveEventArgs e)
        {
            try
            {
                int nodeId       = int.Parse(e.NodeID);
                int targetNodeId = int.Parse(e.TargetNodeID);

                SimpleTasksDataContext ctx = this.DBContext;

                Category category = (from tl in ctx.Categories
                                     where tl.ID == nodeId
                                     select tl).First();

                Category parentlist = (from tl in ctx.Categories
                                       where tl.ID == targetNodeId
                                       select tl).First();

                category.ParentCategory = parentlist;
                ctx.SubmitChanges();
                e.Accept = true;
            }
            catch (Exception exception)
            {
                e.Accept         = false;
                e.RefusalMessage = exception.Message;
            }
        }
Esempio n. 3
0
        public bool DeleteTasks(int[] taskIds)
        {
            if (taskIds == null)
            {
                Ext.Net.X.Msg.Show(new MessageBoxConfig
                {
                    Title   = "Delete tasks error",
                    Message = "Tasks ids are missing",
                    Icon    = MessageBox.Icon.ERROR,
                    Buttons = MessageBox.Button.OK
                });

                return(false);
            }

            try
            {
                SimpleTasksDataContext ctx   = this.DBContext;
                List <Task>            tasks = (from t in ctx.Tasks where taskIds.Contains(t.ID) select t).ToList();

                foreach (Task task in tasks)
                {
                    ctx.Tasks.DeleteOnSubmit(task);
                }

                ctx.SubmitChanges();

                foreach (int id in taskIds)
                {
                    this.Store.Primary.Remove((object)id);
                }

                return(true);
            }
            catch (Exception e)
            {
                Ext.Net.X.Msg.Show(new MessageBoxConfig
                {
                    Title   = "Delete tasks error",
                    Message = e.Message,
                    Icon    = MessageBox.Icon.ERROR,
                    Buttons = MessageBox.Button.OK
                });

                return(false);
            }
        }
Esempio n. 4
0
        public bool ToggleStatus(int[] taskIds, bool?status, int categoryID, string filter)
        {
            try
            {
                SimpleTasksDataContext ctx   = this.DBContext;
                List <Task>            tasks = (from t in ctx.Tasks where taskIds.Contains(t.ID) select t).ToList();

                foreach (Task task in tasks)
                {
                    task.Completed     = status != null ? status.Value : !task.Completed;
                    task.CompletedDate = DateTime.Now;
                }

                ctx.SubmitChanges();

                if (filter != "all")
                {
                    this.BindTasks(categoryID, filter);
                }
                else
                {
                    this.Store.Primary.SuspendEvents(false);
                    foreach (Task task in tasks)
                    {
                        ModelProxy r = this.store.GetById((object)task.ID);
                        r.Set("Completed", task.Completed);
                        r.Set("CompletedDate", new JRawValue(DateTimeUtils.DateNetToJs(task.CompletedDate.Value)));
                    }
                    this.Store.Primary.ResumeEvents();
                    this.Store.Primary.FireEvent("datachanged", new JRawValue(this.Store.Primary.ClientID));
                }

                return(true);
            }
            catch (Exception e)
            {
                Ext.Net.X.Msg.Show(new MessageBoxConfig
                {
                    Title   = "Toggle status error",
                    Message = e.Message,
                    Icon    = MessageBox.Icon.ERROR,
                    Buttons = MessageBox.Button.OK
                });

                return(false);
            }
        }
Esempio n. 5
0
        public void MoveTasks(int[] ids, int categoryID)
        {
            SimpleTasksDataContext ctx = this.DBContext;

            IEnumerable <Task> tasks = from t in ctx.Tasks
                                       where ids.Contains(t.ID)
                                       select t;

            Category category = (from categories in ctx.Categories where categories.ID == categoryID select categories).First();

            foreach (Task task in tasks)
            {
                task.Category = category;
            }

            ctx.SubmitChanges();
        }
Esempio n. 6
0
        public void SaveTask(int taskId, JsonObject values)
        {
            SimpleTasksDataContext ctx = this.DBContext;
            Task task = (from t in ctx.Tasks where t.ID == taskId select t).First();

            task.Title       = values.ContainsKey("Title") ? values["Title"].ToString() : "";
            task.DueDate     = values.ContainsKey("DueDate") ?  DateTime.Parse(values["DueDate"].ToString()) : DateTime.MinValue;
            task.CategoryID  = values.ContainsKey("Name") ?  int.Parse(values["Name"].ToString()) : -1;
            task.Description = values.ContainsKey("Description") ? values["Description"].ToString() : "";

            if (values.ContainsKey("HasReminder") && bool.Parse(values["HasReminder"].ToString()) && values.ContainsKey("Reminder"))
            {
                task.Reminder = DateTime.Parse(values["Reminder"].ToString());
            }

            ctx.SubmitChanges();
        }
Esempio n. 7
0
        void TasksTree_RemoteRemove(object sender, RemoteActionEventArgs e)
        {
            try
            {
                if (e.NodeID.IsEmpty())
                {
                    e.Accept = true;
                    return;
                }

                int nodeId = int.Parse(e.NodeID);

                //root
                if (nodeId == 1)
                {
                    e.Accept         = false;
                    e.RefusalMessage = "The root node can't be deleted";
                }

                SimpleTasksDataContext ctx = this.DBContext;

                Category category = (from tl in ctx.Categories
                                     where tl.ID == nodeId
                                     select tl).First();

                // remove children lists
                foreach (Category childrenList in category.Categories)
                {
                    ctx.Categories.DeleteOnSubmit(childrenList);
                }

                // remove category
                ctx.Categories.DeleteOnSubmit(category);

                ctx.SubmitChanges();
                e.Accept = true;
            }
            catch (Exception exception)
            {
                e.Accept         = false;
                e.RefusalMessage = exception.Message;
            }
        }
Esempio n. 8
0
        void TasksTree_RemoteAppend(object sender, RemoteAppendEventArgs e)
        {
            try
            {
                bool isFolder = bool.Parse(e.ExtraParams["isFolder"]);
                int  folderId = int.Parse(e.ParentNodeID);

                SimpleTasksDataContext ctx = this.DBContext;

                IEnumerable <Category> query = from tl in ctx.Categories
                                               where (tl.IsFolder == isFolder && tl.ParentID == folderId && tl.Name == e.Text)
                                               select tl;

                if (query.Count() > 0)
                {
                    e.Accept         = false;
                    e.RefusalMessage = "Such {0} is existing in the parent folder".FormatWith(isFolder ? "folder" : "category");
                    return;
                }

                Category category = new Category
                {
                    Name     = e.Text,
                    IsFolder = isFolder,
                    ParentID = folderId
                };

                ctx.Categories.InsertOnSubmit(category);
                ctx.SubmitChanges();

                e.NodeID = category.ID.ToString();

                e.Accept = true;
            }
            catch (Exception exception)
            {
                e.Accept         = false;
                e.RefusalMessage = exception.Message;
            }
        }
Esempio n. 9
0
        public bool AddTask(string title, int categoryID, DateTime due)
        {
            if (title.IsEmpty())
            {
                Ext.Net.X.Msg.Show(new MessageBoxConfig
                {
                    Title   = "Add task error",
                    Message = "Title is missing",
                    Icon    = MessageBox.Icon.ERROR,
                    Buttons = MessageBox.Button.OK
                });

                return(false);
            }

            if (due == DateTime.MinValue)
            {
                Ext.Net.X.Msg.Show(new MessageBoxConfig
                {
                    Title   = "Add task error",
                    Message = "Due date is missing",
                    Icon    = MessageBox.Icon.ERROR,
                    Buttons = MessageBox.Button.OK
                });

                return(false);
            }

            try
            {
                SimpleTasksDataContext ctx = this.DBContext;

                Category category = (from tl in ctx.Categories where tl.ID == categoryID select tl).First();

                Task task = new Task();
                task.Title    = title;
                task.Category = category;
                task.DueDate  = due;
                ctx.Tasks.InsertOnSubmit(task);

                ctx.SubmitChanges();

                this.store.Add(new
                {
                    task.ID,
                    task.CategoryID,
                    task.Category.Name,
                    task.Title,
                    task.DueDate
                });

                ((RowSelectionModel)this.GetSelectionModel()).Select((object)task.ID);

                return(true);
            }
            catch (Exception e)
            {
                Ext.Net.X.Msg.Show(new MessageBoxConfig
                {
                    Title   = "Add task error",
                    Message = e.Message,
                    Icon    = MessageBox.Icon.ERROR,
                    Buttons = MessageBox.Button.OK
                });

                return(false);
            }
        }