Beispiel #1
0
 public ActionResult createReport(TaskReportViewModel model)
 {
     try
     {
         using (var db = new ApplicationDbContext())
         {
             var task = db.TaskToDos.Where(x => x.Id == model.TaskId && x.IsActive && !x.IsClosed).SingleOrDefault();
             if (task == null)
             {
                 throw new Exception("Task is not active!");
             }
             var report = new TaskReport {
                 Content      = model.Content,
                 Title        = model.Title,
                 CreatedAt    = DateTime.UtcNow,
                 InternshipId = IMSUserUtil.Id,
                 TaskId       = model.TaskId,
                 IsActive     = true
             };
             db.TaskReports.Add(report);
             db.SaveChanges();
             model.Id        = report.Id;
             model.CreatedAt = report.CreatedAt;
             return(Json(new ImsResult {
                 Data = model
             }));
         }
     }
     catch (Exception e)
     {
         return(Json(new IMS.Common.ImsResult {
             Error = e.Message
         }));
     }
 }
Beispiel #2
0
 public ActionResult updateReport(TaskReportViewModel model)
 {
     try
     {
         using (var db = new ApplicationDbContext())
         {
             var task = db.TaskToDos.Where(x => x.Id == model.TaskId && x.IsActive && !x.IsClosed).SingleOrDefault();
             if (task == null)
             {
                 throw new Exception("Task is not active!");
             }
             var report = db.TaskReports.Where(x => x.Id == model.Id && x.InternshipId == IMSUserUtil.Id).SingleOrDefault();
             if (report == null)
             {
                 throw new Exception("Not Found");
             }
             report.Title   = model.Title;
             report.Content = model.Content;
             db.SaveChanges();
             return(Json(new ImsResult {
                 Data = model
             }));
         }
     }
     catch (Exception e)
     {
         return(Json(new IMS.Common.ImsResult {
             Error = e.Message
         }));
     }
 }