Example #1
0
        public JsonResult SaveTask(Task task)
        {
            var success = false;

            using (TasksEntities dc = new TasksEntities())
            {
                if (task.Category == null)
                {
                    task.Category = " ";
                }
                if (task.EventID > 0)
                {
                    //update all values in a task multipurpose for all save functions specify active or complete on js side
                    var newTask = dc.Tasks.Where(a => a.EventID == task.EventID).FirstOrDefault();
                    if (newTask != null)
                    {
                        newTask.Name        = task.Name;
                        newTask.startDate   = task.startDate;
                        newTask.endDate     = task.endDate;
                        newTask.Description = task.Description;
                        newTask.Category    = task.Category;
                        newTask.assigned    = task.assigned;
                        newTask.completed   = task.completed;
                        newTask.ThemeColor  = task.ThemeColor;
                    }
                }
                else
                {
                    Task     newTask1   = new Task();
                    DateTime?dateOrNull = task.startDate;

                    if (dateOrNull != null)
                    {
                        task.startDate = dateOrNull.Value;
                    }
                    DateTime?dateOrNull2 = task.endDate;

                    if (dateOrNull2 != null)
                    {
                        task.endDate = dateOrNull2.Value;
                    }
                    newTask1.Name        = task.Name;
                    newTask1.startDate   = dateOrNull.Value;
                    newTask1.endDate     = dateOrNull2.Value;
                    newTask1.Description = task.Description;
                    newTask1.Category    = task.Category;
                    newTask1.assigned    = task.assigned;
                    newTask1.createdDate = DateTime.Now;
                    newTask1.completed   = task.completed;
                    newTask1.ThemeColor  = task.ThemeColor;
                    dc.Tasks.Add(newTask1);
                }
                dc.SaveChanges();
                success = true;
            }
            return(new JsonResult {
                Data = new { success = success }
            });
        }
Example #2
0
        public int Add(TaskTable newTask)
        {
            string userName = User.Identity.Name;

            if (ModelState.IsValid)
            {
                newTask.Owner    = userName;
                newTask.IsActive = true;

                db.TaskTables.Add(newTask);
                db.SaveChanges();

                return(newTask.Id);
            }

            return(-1);
        }
Example #3
0
 // post task by id
 public HttpResponseMessage Post([FromBody] Task t)
 {
     using (TasksEntities context = new TasksEntities())
     {
         if (t == null)
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "make sure your task is right"));
         }
         else
         {
             context.Tasks.Add(t);
             context.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Created, t));
         }
     }
 }
Example #4
0
 // delete task by id
 public HttpResponseMessage Delete(int id)
 {
     using (TasksEntities context = new TasksEntities())
     {
         var list = context.Tasks.FirstOrDefault(task => task.Quote == id);
         if (list == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, "There is no tasks to delete"));
         }
         else
         {
             context.Tasks.Remove(list);
             context.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK, list));
         }
     }
 }
Example #5
0
        public JsonResult DeleteTask(int eventID)
        {
            var success = false;

            using (TasksEntities dc = new TasksEntities())
            {
                var oldTask = dc.Tasks.Where(a => a.EventID == eventID).FirstOrDefault();
                if (oldTask != null)
                {
                    dc.Tasks.Remove(oldTask);
                    dc.SaveChanges();
                    success = true;
                }
                return(new JsonResult {
                    Data = new { success = success }
                });
            }
        }
Example #6
0
        // update task by id

        public HttpResponseMessage Put(int id, [FromBody] Task TASK)
        {
            using (TasksEntities context = new TasksEntities())
            {
                var task = context.Tasks.FirstOrDefault(tas => tas.Quote == id);
                if (task == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "There is no task with Id: " + id.ToString() + " to update"));
                }
                else
                {
                    task.QuoteType = TASK.QuoteType;
                    task.Contact   = TASK.Contact;
                    task.Task1     = TASK.Task1;
                    task.DateDue   = TASK.DateDue;
                    context.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, TASK));
                }
            }
        }
Example #7
0
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .Build();

            using (TasksEntities context = new TasksEntities())
            {
                TaskUser newTaskUser = new TaskUser
                {
                    UserId   = Guid.NewGuid(),
                    UserName = "******"
                };

                context.TaskUsers.Add(newTaskUser);
                context.SaveChanges();
            }

            host.Run();
        }
Example #8
0
 public void SaveContext()
 {
     ctx.SaveChanges();
 }