Ejemplo n.º 1
0
 public IActionResult EditTask([FromBody] EditText editTask)
 {
     if (editTask == null)
     {
         output.status      = "Error";
         output.description = "send a json file";
     }
     else
     {
         try
         {
             Task edit = context.tasks.Where(e =>
                                             e.GuserId == editTask.guserId && e.TaskId == editTask.taskId && !e.Status).FirstOrDefault();
             if (edit == null)
             {
                 return(new JsonResult(new List <object>()
                 {
                     new { Error = "no task to edit", Description = "task is either completed or does not exists" }
                 }));
             }
             edit.Title    = editTask.title;
             edit.SubTitle = editTask.subTitle;
             context.SaveChanges();
             output.status      = "success";
             output.description = "task edited successfully";
         }
         catch (Exception e)
         {
             output.status      = "Error";
             output.description = e.Message;
         }
     }
     return(new JsonResult(output));
 }
Ejemplo n.º 2
0
        public IActionResult EditTask([FromBody] EditText EditTask)
        {
            if (EditTask == null)
            {
                return(new JsonResult(new List <object>()
                {
                    new { Error = "no json file", Description = "send a json " }
                }));
            }

            try
            {
                Task edit = (from e in Context.Tasks
                             where e.GuserId == EditTask.GuserId && e.TaskId == EditTask.TaskId
                             select e).FirstOrDefault();
                if (edit == null)
                {
                    return(new JsonResult(new List <object>()
                    {
                        new { Error = "no task to edit", Description = "task is either completed or does not exists" }
                    }));
                }
                edit.Title    = EditTask.Title;
                edit.SubTitle = EditTask.SubTitle;
                Context.SaveChanges();
                return(Ok("Task updated"));
            }
            catch (Exception e)
            {
                return(new JsonResult(new List <object>()
                {
                    new { Error = "invalid Json", Description = "Json sent has invalid key value pair" }
                }));
            }
        }
        public IActionResult Details(int id)
        {
            using (ToDoDbContext db = new ToDoDbContext())
            {
                Task task = db.Tasks.FirstOrDefault(x => x.Id == id);
                if (task == null)
                {
                    RedirectToAction("Index");
                }

                return(View(task));
            }
        }
        public IActionResult Delete(int id)
        {
            using (ToDoDbContext db = new ToDoDbContext())
            {
                Task task = db.Tasks.FirstOrDefault(x => x.Id == id);
                if (task == null)
                {
                    RedirectToAction("Index");
                }

                db.Tasks.Remove(task);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public IActionResult Edit(Task task)
        {
            if (!ModelState.IsValid)
            {
                RedirectToAction("Index");
            }

            using (ToDoDbContext db = new ToDoDbContext())
            {
                Task taskToEdit = db.Tasks.FirstOrDefault(x => x.Id == task.Id);
                taskToEdit.Title    = task.Title;
                taskToEdit.Comments = task.Comments;
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public IActionResult Create(string title, string comments)
        {
            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(comments))
            {
                return(RedirectToAction("Index"));
            }

            Task task = new Task(title, comments);

            using (ToDoDbContext db = new ToDoDbContext())
            {
                db.Add(task);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
        public IActionResult AddTask([FromBody] AddTaskDto AddTask)
        {
            if (AddTask == null)
            {
                return(new JsonResult(new List <object>()
                {
                    new { Error = "no json file", Description = "send a json " }
                }));
            }

            Task Tasks = new Task();

            try
            {
                Tasks.Title    = AddTask.Title;
                Tasks.SubTitle = AddTask.SubTitle;
                Tasks.Status   = AddTask.Status;
                User user = (from e in Context.Users
                             where e.GuserId == AddTask.GuserId
                             select e).FirstOrDefault();

                if (user != null)
                {
                    Tasks.GuserId = AddTask.GuserId;
                    Tasks.UserId  = user.UserId;
                }
                else
                {
                    return(new JsonResult(new List <object>()
                    {
                        new { Error = "user does not exists", Description = "the user for which you are entering task does not exists" }
                    }));
                }
                Context.Tasks.Add(Tasks);
                Context.SaveChanges();
                return(Ok("Task added"));
            }
            catch (Exception e)
            {
                return(new JsonResult(new List <object>()
                {
                    new { Error = "Invalid Entry in Json", Description = "send a json " }
                }));
            }
        }
Ejemplo n.º 8
0
        public IActionResult AddTask([FromBody] AddTaskDto addTask)
        {
            if (addTask == null)
            {
                output.status      = "Error";
                output.description = "send a json file";
            }
            else
            {
                Task task = new Task
                {
                    Title    = addTask.title,
                    SubTitle = addTask.subTitle,
                    Status   = addTask.status
                };
                try
                {
                    var user = context.users.Where(e => e.GuserId == addTask.guserId).FirstOrDefault();

                    if (user != null)
                    {
                        task.GuserId = addTask.guserId;
                        task.UserId  = user.UserId;
                    }
                    else
                    {
                        output.status      = "Error";
                        output.description = "the user for which you are entering task does not exists";
                    }
                    context.tasks.Add(task);
                    context.SaveChanges();
                    output.status      = "success";
                    output.description = "task added successfully";
                }
                catch (Exception e)
                {
                    output.status      = "Error";
                    output.description = e.Message;
                }
            }
            return(new JsonResult(output));
        }
Ejemplo n.º 9
0
 public IActionResult Upsert(TaskVM taskVM)
 {
     if (ModelState.IsValid)
     {
         if (taskVM != null)
         {
             ToDoList.Models.Task objFromDb = _unitOfWork.Task.Get(taskVM.Task.id);
         }
         if (taskVM.Task.id == 0)
         {
             _unitOfWork.Task.Add(taskVM.Task);
         }
         else
         {
             _unitOfWork.Task.Update(taskVM.Task);
         }
         _unitOfWork.Save();
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         taskVM.TypeList = _unitOfWork.TaskType.GetAll().Select(i => new SelectListItem()
         {
             Text  = i.Type,
             Value = i.TaskTypeId.ToString()
         });
         taskVM.EmployeeList = _unitOfWork.Employee.GetAll().Select(i => new SelectListItem()
         {
             Text  = i.Name,
             Value = i.EmployeeId.ToString()
         });
         if (taskVM.Task.id != 0)
         {
             taskVM.Task = _unitOfWork.Task.Get(taskVM.Task.id);
         }
     }
     return(View(taskVM));
 }
Ejemplo n.º 10
0
 public ActionResult Edit(Task task)
 {
     db.Entry(task).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return RedirectToAction("Index");
 }
Ejemplo n.º 11
0
 public ActionResult Create(Task task)
 {
     db.Tasks.Add(task);
     db.SaveChanges();
     return RedirectToAction("Index");
 }