public void Delete(int id)
        {
            // string owner = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
            string owner = User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

            Models.TaskItem task = db.Where(t => t.Owner.Equals(owner) && t.Id.Equals(id)).FirstOrDefault();
            db.Remove(task);
        }
 public void setSelectedItemById(string id)
 {
     foreach (Models.TaskItem task in allItems)
     {
         if (task.id == id)
         {
             selectedItem = task;
         }
     }
 }
 public void RemoveTaskItem(string id)
 {
     this.allItems.Remove(this.selectedItem);
     using (var statement = App.conn.Prepare("DELETE FROM TaskItem WHERE Id = ?"))
     {
         statement.Bind(1, id);
         statement.Step();
     }
     // set selectedItem to null after remove
     this.selectedItem = null;
 }
        public void Post(Models.TaskItem task)
        {
            if (task.Text == null || task.Text == string.Empty)
            {
                throw new WebException("Please provide a task description");
            }

            // string owner = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
            string owner = User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

            task.Owner        = owner;
            task.Completed    = false;
            task.DateModified = DateTime.UtcNow;
            db.Add(task);
        }
Exemple #5
0
        public void AddingTaskInListAndTask()
        {
            //Arrange
            var db = new DbContextMock.DbEmptyContextMocker().GetContext();

            db.TaskLists.Add(new Models.TaskList()
            {
                ListID    = 1,
                ListName  = "test list",
                ProjectID = 5
            });
            db.SaveChanges();

            //Act
            var list = db.TaskLists.Find(1);
            var task = new Models.TaskItem()
            {
                ID                = 1,
                TaskName          = "test task",
                OriginalProjectID = 5,
                TasksInLists      = new List <Models.TaskInList>()
                {
                    new Models.TaskInList()
                    {
                        List    = list,
                        OrderNo = 1
                    }
                }
            };

            db.Add(task);
            db.SaveChanges();

            //Assert

            //task and taskinlist added
            Assert.NotEmpty(db.TaskItems);
            Assert.NotEmpty(db.TasksInLists);

            var taskinlistindb = db.TasksInLists.First();
            var taskindb       = db.TaskItems.First();

            Assert.Equal(taskindb.ID, taskinlistindb.TaskID);

            db.Dispose();
        }
Exemple #6
0
        public async Task <IActionResult> PostTaskItem([FromBody] Models.TaskItem taskItem, int?ListID = null)
        {
            try
            {
                if (taskItem.ID != null)
                {
                    return(new BadRequestObjectResult(ModelState));
                }

                if (!ModelState.IsValid)
                {
                    return(new BadRequestObjectResult(ModelState));
                }
                await dbContext.TaskItems.AddAsync(taskItem);

                await dbContext.SaveChangesAsync();

                var result = dbContext.Entry(taskItem).Entity;

                //TODO taskinlist update
                if (ListID.HasValue)
                {
                    var tilresult = dbContext.TasksInLists.Count((x) => x.ListID == ListID);
                    var til       = new Models.TaskInList()
                    {
                        ListID  = ListID.Value,
                        TaskID  = result.ID.Value,
                        OrderNo = tilresult + 1
                    };
                    await dbContext.TasksInLists.AddAsync(til);

                    await dbContext.SaveChangesAsync();
                }

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(new ObjectResult(e)
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError
                });
            }
        }
 public void updatetaskitem(string id, string title, string description, DateTime datetime, BitmapSource bitmapimage, string filepath, string username, string comment, string participatants)
 {
     if (this.selectedItem != null)
     {
         using (var tasklist = App.conn.Prepare("update taskitem set Title = ?, Detail = ?, Datetime = ?, Filepath = ?, Username = ?, Comment = ?, Participatants = ? where id = ?"))
         {
             tasklist.Bind(1, title);
             tasklist.Bind(2, description);
             tasklist.Bind(3, datetime.Date.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo));
             tasklist.Bind(4, filepath);
             tasklist.Bind(5, username);
             tasklist.Bind(6, comment);
             tasklist.Bind(7, participatants);
             tasklist.Bind(8, id);
             tasklist.Step();
         }
     }
     getItemFromDB();
     this.selectedItem = null;
 }
 public void RemoveTaskItem(string id)
 {
     this.allItems.Remove(this.selectedItem);
     using (var statement = App.conn.Prepare("DELETE FROM TaskItem WHERE Id = ?"))
     {
         statement.Bind(1, id);
         statement.Step();
     }
     // set selectedItem to null after remove
     this.selectedItem = null;
 }
 public void updatetaskitem(string id, string title, string description, DateTime datetime, BitmapSource bitmapimage, string filepath, string username, string comment)
 {
     if (this.selectedItem != null)
     {
         using (var tasklist = App.conn.Prepare("update taskitem set Title = ?, Detail = ?, Datetime = ?, Filepath = ?, Username = ?, Comment = ? where id = ?"))
         {
             tasklist.Bind(1, title);
             tasklist.Bind(2, description);
             tasklist.Bind(3, datetime.Date.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo));
             tasklist.Bind(4, filepath);
             tasklist.Bind(5, username);
             tasklist.Bind(6, comment);
             tasklist.Bind(7, id);
             tasklist.Step();
         }
     }
     getItemFromDB();
     this.selectedItem = null;
 }