public async Task <IActionResult> Create()
        {
            var author = await _userManager.FindByNameAsync(User.Identity.Name);

            var model = new CreateReportViewModel
            {
                AuthorId   = author.Id,
                Managers   = SystemOperations.GetProjectManagerViewModels(author.Id, _managerData), //List of all managers of this user
                Projects   = SystemOperations.GetInProgressProjectViewModels(_projectService),      //All in progress projects
                Activities = _activityData.GetParentActivities().ToList()                           //List of main activities
            };

            return(View(model));
        }
 public IActionResult Create(CreateReportViewModel model)
 {
     model.Managers   = SystemOperations.GetProjectManagerViewModels(model.AuthorId, _managerData);
     model.Projects   = SystemOperations.GetInProgressProjectViewModels(_projectService);
     model.Activities = _activityData.GetParentActivities().ToList();
     if (ModelState.IsValid)
     {
         if (model.TaskStartTime >= model.TaskEndTime)
         {
             ModelState.AddModelError("", "زمان ورود و خروج را بررسی کنید.");
             return(View(model));
         }
         //Save report Attachment
         var report = new Report
         {
             Title           = model.Title,
             Text            = model.Text,
             ProjectId       = model.ProjectId,
             AuthorId        = model.AuthorId,
             ActivityId      = model.ActivityId,
             SubActivityId   = model.SubActivityId,
             ActivityApendix = model.ActivityApendix,
             TaskStartTime   = model.TaskStartTime,
             TaskEndTime     = model.TaskEndTime,
             Date            = DateTime.Now,
             AttachmentName  = model.AttachmentName
         };
         var savedReport = _reportData.Add(report, model.ProjectManagerIds); //Saving Report
         if (savedReport == null)
         {
             ModelState.AddModelError("", "مشکل در ایجاد گزارش.");
             return(View(model));
         }
         return(RedirectToAction("ManageReports", "Account"));
     }
     return(View(model));
 }
 public IActionResult Edit(CreateReportViewModel model)
 {
     model.Managers   = SystemOperations.GetProjectManagerViewModels(model.AuthorId, _managerData);
     model.Projects   = SystemOperations.GetInProgressProjectViewModels(_projectService);
     model.Activities = _activityData.GetParentActivities().ToList();
     if (ModelState.IsValid)
     {
         if (model.TaskStartTime >= model.TaskEndTime)
         {
             ModelState.AddModelError("", "زمان شروع و پایان را بررسی کنید.");
             return(View(model));
         }
         //Save report Attachment
         var report = _reportData.Get(model.Id);
         report.Title           = model.Title;
         report.Text            = model.Text;
         report.ProjectId       = model.ProjectId;
         report.ActivityId      = model.ActivityId;
         report.SubActivityId   = model.SubActivityId == 0 ? null : model.SubActivityId;
         report.ActivityApendix = model.ActivityApendix;
         report.TaskStartTime   = model.TaskStartTime;
         report.TaskEndTime     = model.TaskEndTime;
         if (model.AttachmentName != null) //preventing from saving null instead of last attachment
         {
             report.AttachmentName = model.AttachmentName;
         }
         var result = _reportData.Update(report, model.ProjectManagerIds);
         if (!result)
         {
             ModelState.AddModelError("", "مشکل در بروزرسانی!");
             return(View(model));
         }
         return(RedirectToAction("ManageReports", "Account"));
     }
     return(View(model));
 }
        public IActionResult Edit(short id)
        {
            var report = _reportData.Get(id);

            if (report == null)
            {
                return(NotFound());
            }
            if (report.Author.UserName != User.Identity.Name)
            {
                return(RedirectToAction("AccessDenied", "Home"));
            }
            var model = new CreateReportViewModel
            {
                Id                = report.Id,
                AuthorId          = report.AuthorId,
                ActivityId        = report.Activity.Id,
                SubActivityId     = report.SubActivityId ?? null,
                ActivityApendix   = report.ActivityApendix,
                TaskStartTime     = report.TaskStartTime,
                TaskEndTime       = report.TaskEndTime,
                ProjectId         = report.ProjectId,
                Managers          = SystemOperations.GetProjectManagerViewModels(report.AuthorId, _managerData),
                Projects          = SystemOperations.GetInProgressProjectViewModels(_projectService),
                Activities        = _activityData.GetParentActivities().ToList(), //List of main activities
                ProjectManagerIds = report.ProjectManagers.Select(pm => pm.ManagerId).ToList(),
                Title             = report.Title,
                Text              = report.Text,
                //If any of project managers submited report with this report
                IsSubmitedByManager = report.ManagerReports != null && report.ManagerReports.Any() ? true : false,
                AttachmentName      = report.AttachmentName != null ? report.AttachmentName : null
            };


            return(View(model));
        }