public async Task <IActionResult> DeleteConfirmed(int id)
        {
            if (!AuthenticationHelper.isAuthorizedUser(HttpContext.Session.GetString("Username")))
            {
                Response.Redirect("/Login");
            }

            //Fetch the task to be delted
            Task task = _context.Tasks.Where(x => x.TaskId == id).FirstOrDefault();

            _context.Tasks.Remove(task);
            await _context.SaveChangesAsync();

            //Redirect to Tasks page
            return(RedirectToAction(nameof(Index)));
        }
        /// <summary>
        /// Fills the View Model from task
        /// </summary>
        /// <returns>Task ConversationsView Model.</returns>
        /// <param name="ts">Task</param>
        private TaskConversationsViewModel FillTaskConversationVM(Task ts)
        {
            //Populate Data for View Model
            TaskConversationsViewModel vm = new TaskConversationsViewModel();

            vm.Title      = ts.Title;
            vm.TaskId     = ts.TaskId;
            vm.AssignedTo = ts.AssignedTo.Username;
            vm.CreatedBy  = ts.CreatedBy.Username;
            vm.Priority   = ts.Priority;
            vm.DueDate    = ts.DueDate;
            //Load Feedback using lazy loading
            vm.Feedbacks = (ICollection <Feedback>)_context.Feedbacks
                           .Include(feedback => feedback.User)
                           .Where(x => x.TaskId == ts.TaskId).ToList();
            return(vm);
        }
        /// <summary>
        /// Updates the task.
        /// </summary>
        /// <returns>Success or Failure.</returns>
        /// <param name="vm">TaskDetailsViewModel.</param>
        protected async Task <Boolean> UpdateTask(TaskDetailsViewModel vm)
        {
            //Check for error if any
            try
            {
                //Fetch task which needs to be updated
                Task task = _context.Tasks.Where(x => x.TaskId == vm.TaskId).FirstOrDefault();

                task.Priority   = vm.Priority;
                task.Status     = vm.Status;
                task.DueDate    = vm.DueDate;
                task.Title      = vm.Title;
                task.Severity   = vm.Severity;
                task.AssignedTo = _context.Users.Where(usr => usr.Username == vm.AssignedTo).FirstOrDefault();

                //Check FIle count
                if (vm.Files.Count() > 0)
                {
                    using (var ms = new MemoryStream())
                    {
                        vm.Files.FirstOrDefault().CopyTo(ms);
                        var        fileBytes  = ms.ToArray();
                        Attachment attachment = new Models.Attachment()
                        {
                            file = fileBytes
                        };
                        attachment.Filename = vm.Files.FirstOrDefault().FileName;
                        _context.Attachments.Add(attachment);
                        task.Attachment = attachment;
                    }
                }
                //Update Task
                _context.Tasks.Update(task);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                return(false);
            }
        }
        /// <summary>
        /// Fills the task details vm.
        /// </summary>
        /// <returns>The task details vm.</returns>
        /// <param name="task">Task.</param>
        private TaskDetailsViewModel fillTaskDetailsVM(Task task)
        {
            //Fill View Model
            TaskDetailsViewModel vm = new TaskDetailsViewModel()
            {
                TaskId         = task.TaskId,
                AssignedTo     = task.AssignedTo.Username,
                CreatedBy      = task.CreatedBy.Username,
                DueDate        = task.DueDate,
                Created        = task.Created,
                Status         = task.Status,
                Priority       = task.Priority,
                Severity       = task.Severity,
                Title          = task.Title,
                AttachmentName = task.Attachment.Filename
            };

            return(vm);
        }