public ActionResult Edit(RecipTaskEditModel model)
        {
            try
            {
                using (var context = new TaskManagerContext())
                {
                    var task = context.Tasks.Include(x => x.TaskEeventLogs).FirstOrDefault(x => x.TaskId == model.TaskId);
                    if (task != null)
                    {
                        if ((string.IsNullOrEmpty(task.ResultComment) && !string.IsNullOrEmpty(model.ResultComment)) ||
                            (!string.IsNullOrEmpty(task.ResultComment) && !task.ResultComment.Equals(model.ResultComment, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            task.TaskEeventLogs.Add(new TaskEeventLog
                            {
                                EventDateTime = DateTime.Now,
                                PropertyName  = "ResultComment",
                                UserId        = WebSecurity.CurrentUserId,
                                OldValue      = task.ResultComment,
                                NewValue      = model.ResultComment
                            });
                            task.ResultComment = model.ResultComment;
                        }
                        if (task.CompleteDate == null)
                        {
                            task.TaskEeventLogs.Add(new TaskEeventLog
                            {
                                EventDateTime = DateTime.Now,
                                PropertyName  = "CompleteDate",
                                UserId        = WebSecurity.CurrentUserId,
                                OldValue      = task.CompleteDate.HasValue ? task.CompleteDate.Value.ToString(ModelHelper.DateTimeFormatFull) : null,
                                NewValue      = DateTime.Now.ToString(ModelHelper.DateTimeFormatFull)
                            });
                            task.CompleteDate = DateTime.Now;
                        }
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(RedirectToAction("Index"));
        }
 public ActionResult Edit(int taskId)
 {
     try
     {
         Task task;
         using (var context = new TaskManagerContext())
         {
             task = context.Tasks.Include(x => x.TaskSender)
                    .Include(x => x.TaskPriority)
                    .Include(x => x.TaskSender)
                    .Include(x => x.Comments)
                    .FirstOrDefault(x => x.TaskId == taskId);
             if (task != null)
             {
                 task.IsRecipientViewed = true;
                 context.SaveChanges();
             }
         }
         if (task != null)
         {
             var taskEdit = new RecipTaskEditModel
             {
                 AssignDateTime = task.AssignDateTime.Value,
                 CreationDate   = task.CreateDate,
                 Deadline       = task.Deadline.Value,
                 PriorityName   = task.TaskPriority.PriorityName,
                 SenderName     = task.TaskSender.UserFullName,
                 TaskId         = task.TaskId,
                 TaskText       = task.TaskText,
                 ResultComment  = task.ResultComment,
                 CompleteDate   = task.CompleteDate,
                 CommentsCount  = task.Comments.Count
             };
             return(View(taskEdit));
         }
     }
     catch (Exception)
     {
         //throw;
     }
     return(RedirectToAction("Index"));
 }