Beispiel #1
0
        public IHttpActionResult PutTask_Table(ParentTaskView pt)
        {
            return(Ok());

            //if (id != task_Table.Task_ID)
            //{
            //    return BadRequest();
            //}

            //db.Entry(task_Table).State = EntityState.Modified;

            //try
            //{
            //    db.SaveChanges();
            //}
            //catch (DbUpdateConcurrencyException)
            //{
            //    if (!Task_TableExists(id))
            //    {
            //        return NotFound();
            //    }
            //    else
            //    {
            //        throw;
            //    }
            //}

            //return StatusCode(HttpStatusCode.NoContent);
        }
Beispiel #2
0
        public void PutSupplier_ShouldFail_WhenDifferentID()
        {
            var controller = new Task_Controller(new TestContext());

            var            task = GetDemoTask();
            ParentTaskView pt   = new ParentTaskView();

            pt = new ParentTaskView
            {
                Start_Date  = task.Start_Date,
                End_Date    = task.End_Date,
                Priority    = task.Priority,
                IsActive    = task.IsActive,
                Parent_Task = task.Parent_Task_Table.Parent_Task,
                Task        = task.Task,
            };
            var result = controller.PutTask_Table(pt, 1000);

            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
Beispiel #3
0
        public void PostTask_ShouldReturnSameItem()
        {
            var controller = new Task_Controller(new TestContext());

            var            task = GetDemoTask();
            ParentTaskView pt   = new ParentTaskView();

            pt = new ParentTaskView
            {
                Start_Date  = task.Start_Date,
                End_Date    = task.End_Date,
                Priority    = task.Priority,
                IsActive    = task.IsActive,
                Parent_Task = task.Parent_Task_Table.Parent_Task,
                Task        = task.Task
            };
            var result = controller.PostTask_Table(pt) as CreatedAtRouteNegotiatedContentResult <ParentTaskView>;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteName, "DefaultApi");
            Assert.AreEqual(result.RouteValues["id"], result.Content.Task_ID);
            Assert.AreEqual(result.Content.Task, task.Task);
        }
Beispiel #4
0
        public IHttpActionResult PostTask_Table(ParentTaskView pt)
        {
            if (pt.IsActive == null)
            {
                if (pt.Task_ID == null)
                {
                    Parent_Task_Table p = new Parent_Task_Table();
                    Task_Table        t = new Task_Table();

                    //Parent Task Table insert
                    p.Parent_Task = pt.Parent_Task;
                    db.Parent_Task_Table.Add(p);
                    db.SaveChanges();

                    int latestParentId = Convert.ToInt32(p.Parent_ID);

                    //Task Table insert
                    t.Parent_ID  = latestParentId;
                    t.Task       = pt.Task;
                    t.Start_Date = Convert.ToDateTime(pt.Start_Date);
                    t.End_Date   = pt.End_Date;
                    t.Priority   = Convert.ToInt32(pt.Priority);
                    db.Task_Table.Add(t);
                    //  System.IO.File.WriteAllText(@"D:\taskapilog2.txt","Add method success");
                    db.SaveChanges();
                }
                else if (pt.Task_ID != null)
                {
                    int?latestParentId  = null;
                    Parent_Task_Table p = new Parent_Task_Table();
                    //System.IO.File.WriteAllText(@"D:\taskapilogUp.txt", "Update method");

                    if (pt.Parent_ID == null)
                    {
                        //Parent Task Table insert

                        p.Parent_Task = pt.Parent_Task;
                        db.Parent_Task_Table.Add(p);
                        db.SaveChanges();
                        latestParentId = Convert.ToInt32(p.Parent_ID);
                    }
                    else
                    {
                        //System.IO.File.WriteAllText(@"D:\taskapilogUp1.txt", pt.Parent_ID + "");
                        var ParentTask_TableInDb = db.Parent_Task_Table.SingleOrDefault(p1 => p1.Parent_ID == pt.Parent_ID);
                        if (ParentTask_TableInDb == null)
                        {
                            throw new HttpResponseException(HttpStatusCode.NotFound);
                        }

                        //Parent Task Table update
                        ParentTask_TableInDb.Parent_Task = pt.Parent_Task;
                        db.SaveChanges();
                    }

                    var Task_TableInDb = db.Task_Table.SingleOrDefault(c => c.Task_ID == pt.Task_ID);
                    if (Task_TableInDb == null)
                    {
                        throw new HttpResponseException(HttpStatusCode.NotFound);
                    }

                    //Task Table update
                    if (latestParentId != null)
                    {
                        Task_TableInDb.Parent_ID = latestParentId;
                    }

                    Task_TableInDb.Task       = pt.Task;
                    Task_TableInDb.Start_Date = Convert.ToDateTime(pt.Start_Date);
                    Task_TableInDb.End_Date   = pt.End_Date;
                    Task_TableInDb.Priority   = Convert.ToInt32(pt.Priority);

                    //  System.IO.File.WriteAllText(@"D:\taskapilog2.txt","Add method success");
                    db.SaveChanges();
                }
            }
            else if (pt.IsActive == "N")
            {
                //End Task Code
                var Task_TableIndb = db.Task_Table.SingleOrDefault(c1 => c1.Task_ID == pt.Task_ID);
                if (Task_TableIndb == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
                Task_TableIndb.IsActive = pt.IsActive;
                db.SaveChanges();
            }
            // return CreatedAtRoute("DefaultApi", new { id = t.Task_ID }, pt);
            return(Ok());
        }