Пример #1
0
        public ActionResult Create(TaskDto taskDto)
        {
            var context = new DatabaseContext();
            var createdTask = context.Tasks.Add(new Task
            {
                Name = taskDto.Name,
                Description = taskDto.Description,
                TypeId = taskDto.TypeId,
                Created = DateTime.Now
            });
            context.SaveChanges();

            var taskType = context.TaskTypes.FirstOrDefault(t => t.Id == createdTask.TypeId);

            return Json(new TaskDto
            {
                Id = createdTask.Id,
                Name = createdTask.Name,
                Description = createdTask.Description,
                TypeId = createdTask.TypeId,
                Created = createdTask.Created,
                TypeString = taskType != null ? taskType.Name : "",
                CreatedString = createdTask.Created.ToString("yy-MM-dd")
            });
        }
Пример #2
0
 public ActionResult Remove(int id)
 {
     var context = new DatabaseContext();
     var task = context.Tasks.Find(id);
     if (task != null)
     {
         context.Tasks.Remove(task);
         context.SaveChanges();
     }
     return Json(new { }, JsonRequestBehavior.AllowGet);
 }
Пример #3
0
        public ActionResult Index()
        {
            var context = new DatabaseContext();
            var taskListVm = new TaskIndexViewModel
            {
                Tasks = context.Tasks.ToList().Select(t => new TaskDto { Id = t.Id, Name = t.Name, Description = t.Description, TypeId = t.TypeId, Created = t.Created, TypeString = t.Type.Name, CreatedString = t.Created.ToString("yy-MM-dd") }).ToList(),
                Types = context.TaskTypes.Select(t => new TaskTypeDto { Id = t.Id, Name = t.Name }).ToList(),
                Model = new TaskDto()
            };

            return View(taskListVm);
        }