public IActionResult Post(WebApiLink apiLink)
        {
            var newLink = (Link)apiLink;

            _context.Links.Add(newLink);
            _context.SaveChanges();

            return(Ok(new
            {
                tid = newLink.Id,
                action = "inserted"
            }));
        }
Ejemplo n.º 2
0
        public IHttpActionResult CreateLink(LinkDto linkDto)
        {
            var newLink = (Link)linkDto;

            db.Links.Add(newLink);
            db.SaveChanges();

            return(Ok(new
            {
                tid = newLink.Id,
                action = "inserted"
            }));
        }
Ejemplo n.º 3
0
 public IHttpActionResult Post(Task task)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Tasks.Add(task);
             db.SaveChanges();
             return(Json(GanttResponseHelper.GetResult("inserted", task.id)));
         }
     }
     catch (Exception) { }
     return(Json(GanttResponseHelper.GetResult("error", null)));
 }
Ejemplo n.º 4
0
        public IActionResult Post(WebApiTask apiTask)
        {
            var newTask = (Task)apiTask;

            newTask.SortOrder = _context.Tasks.Max(t => t.SortOrder) + 1;
            _context.Tasks.Add(newTask);
            _context.SaveChanges();

            return(Ok(new
            {
                tid = newTask.Id,
                action = "inserted"
            }));
        }
Ejemplo n.º 5
0
        private void _CreateTask(GanttContext db, HttpContext context)
        {
            var form    = context.Request.Params;
            var apiTask = new TaskDto
            {
                text       = form["text"],
                start_date = form["start_date"],
                duration   = int.Parse(form["duration"]),
                progress   = !string.IsNullOrEmpty(form["progress"]) ? decimal.Parse(form["progress"]) : 0,
                parent     = !string.IsNullOrEmpty(form["progress"]) ? int.Parse(form["parent"]) : 0,
                type       = form["type"]
            };

            var newTask = (Task)apiTask;

            newTask.SortOrder = _db.Tasks.Max(t => t.SortOrder) + 1;
            db.Tasks.Add(newTask);
            db.SaveChanges();

            _Response(new
            {
                tid    = newTask.Id,
                action = "inserted"
            }, context);
        }
Ejemplo n.º 6
0
        public ContentResult Save(FormCollection form)
        {
            var dataActions = GanttRequest.Parse(form, Request.QueryString["gantt_mode"]);

            try
            {
                foreach (var ganttData in dataActions)
                {
                    switch (ganttData.Mode)
                    {
                    case GanttMode.Tasks:
                        UpdateTasks(ganttData);
                        break;

                    case GanttMode.Links:
                        UpdateLinks(ganttData);
                        break;
                    }
                }
                db.SaveChanges();
            }
            catch
            {
                // return error to client if something went wrong
                dataActions.ForEach(g => { g.Action = GanttAction.Error; });
            }
            return(GanttRespose(dataActions));
        }
Ejemplo n.º 7
0
        public IHttpActionResult EditTask(int id, TaskDto taskDto)
        {
            var updatedTask = (Task)taskDto;

            updatedTask.Id = id;

            if (!string.IsNullOrEmpty(taskDto.target))
            {
                // reordering occurred
                this._UpdateOrders(updatedTask, taskDto.target);
            }

            db.Entry(updatedTask).State = EntityState.Modified;
            db.SaveChanges();

            return(Ok(new
            {
                action = "updated"
            }));
        }
Ejemplo n.º 8
0
        public IHttpActionResult Post(Task task)
        {
            short       grID    = 0;
            HttpContext context = HttpContext.Current;

            try
            {
                if (ModelState.IsValid)
                {
                    db.Tasks.Add(task);
                    db.SaveChanges();
                    grID = sup.grID();
                    sup.groupTaskAdd(grID, task.id);

                    return(Json(GanttResponseHelper.GetResult("inserted", task.id)));
                }
            }
            catch (Exception) { }

            return(Json(GanttResponseHelper.GetResult("error", null)));
        }
Ejemplo n.º 9
0
        public IHttpActionResult DeleteLink(int id)
        {
            var link = db.Links.Find(id);

            if (link != null)
            {
                db.Links.Remove(link);
                db.SaveChanges();
            }
            return(Ok(new
            {
                action = "deleted"
            }));
        }
Ejemplo n.º 10
0
        private void _DeleteTask(GanttContext db, HttpContext context)
        {
            var id   = int.Parse((string)context.Request.RequestContext.RouteData.Values["id"]);
            var task = db.Tasks.Find(id);

            if (task != null)
            {
                db.Tasks.Remove(task);
                db.SaveChanges();
            }
            _Response(new
            {
                action = "deleted"
            }, context);
        }
Ejemplo n.º 11
0
        private void _CreateLink(GanttContext db, HttpContext context)
        {
            var form    = context.Request.Params;
            var linkDto = new LinkDto
            {
                type   = form["type"],
                source = int.Parse(form["source"]),
                target = int.Parse(form["target"]),
            };

            var newLink = (Link)linkDto;

            db.Links.Add(newLink);
            db.SaveChanges();

            _Response(new
            {
                tid    = newLink.Id,
                action = "inserted"
            }, context);
        }
Ejemplo n.º 12
0
        private void _UpdateTask(GanttContext db, HttpContext context)
        {
            var form    = context.Request.Params;
            var id      = int.Parse((string)context.Request.RequestContext.RouteData.Values["id"]);
            var apiTask = new TaskDto
            {
                id         = id,
                text       = form["text"],
                start_date = form["start_date"],
                duration   = int.Parse(form["duration"]),
                progress   = !string.IsNullOrEmpty(form["progress"]) ? decimal.Parse(form["progress"]) : 0,
                parent     = !string.IsNullOrEmpty(form["progress"]) ? int.Parse(form["parent"]) : 0,
                type       = form["type"],
                target     = form["target"]
            };

            var updatedTask = (Task)apiTask;

            var dbTask = db.Tasks.Find(updatedTask.Id);

            dbTask.Text      = updatedTask.Text;
            dbTask.StartDate = updatedTask.StartDate;
            dbTask.Duration  = updatedTask.Duration;
            dbTask.ParentId  = updatedTask.ParentId;
            dbTask.Progress  = updatedTask.Progress;
            dbTask.Type      = updatedTask.Type;

            if (!string.IsNullOrEmpty(apiTask.target))
            {
                // reordering occurred
                this._UpdateOrders(db, dbTask, apiTask.target);
            }

            db.SaveChanges();

            _Response(new
            {
                action = "updated"
            }, context);
        }
Ejemplo n.º 13
0
        private void _UpdateLink(GanttContext db, HttpContext context)
        {
            var form    = context.Request.Params;
            var id      = int.Parse((string)context.Request.RequestContext.RouteData.Values["id"]);
            var linkDto = new LinkDto
            {
                id     = id,
                type   = form["type"],
                source = int.Parse(form["source"]),
                target = int.Parse(form["target"]),
            };

            var clientLink = (Link)linkDto;

            db.Entry(clientLink).State = EntityState.Modified;
            db.SaveChanges();

            _Response(new
            {
                action = "updated"
            }, context);
        }
Ejemplo n.º 14
0
 public void Save()
 {
     context.SaveChanges();
 }