コード例 #1
0
        public IActionResult Details()
        {
            string taskId = this.Request.QueryData["id"].ToString();

            Task task = this.tasksService.GetTaskById(taskId);

            if (task == null)
            {
                return(this.RedirectToAction("/Home/Index"));
            }

            List <string> affectedSectors = task.AffectedSectors
                                            .Select(ts => this.sectorsService.GetSectorById(ts.SectorId).Name)
                                            .ToList();

            DetailsTaskViewModel taskViewModel = new DetailsTaskViewModel
            {
                Title           = task.Title,
                Description     = task.Description,
                Participants    = task.ParticipantsString,
                Level           = task.AffectedSectors.Count,
                DueDate         = task.DueDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                AffectedSectors = string.Join(", ", affectedSectors)
            };

            this.Model["Task"] = taskViewModel;
            return(this.View());
        }
コード例 #2
0
        public IActionResult Details()
        {
            var taskId = int.Parse(this.Request.QueryData["id"].ToString());

            var task = this.context.Tasks.Include(t => t.TasksSectors).ThenInclude(ts => ts.Sector).FirstOrDefault(t => t.Id == taskId);

            if (task == null)
            {
                return(this.RedirectToAction("/"));
            }

            var affectedSectorsNames = string.Join(", ", task.TasksSectors.Select(ts => ts.Sector.Name));

            var detailsTaskViewModel = new DetailsTaskViewModel
            {
                Title           = task.Title,
                Description     = task.Description,
                AffectedSectors = affectedSectorsNames,
                DueDate         = task.DueDate.ToString("dd/MM/yyyy"),
                Participants    = task.Participants,
                Level           = task.TasksSectors.Count.ToString()
            };

            this.Model.Data["TaskDetails"] = detailsTaskViewModel;

            return(this.View());
        }
コード例 #3
0
        public IHttpResponse Details(int id)
        {
            var task = Db.Tasks.Include(x => x.AffectedSectors).FirstOrDefault(x => x.Id == id);

            var sectors = Db.TaskSectors.Include(x => x.Sector).Where(x => x.TaskId == task.Id)
                          .Select(x => x.Sector.Name).ToList();

            var model = new DetailsTaskViewModel
            {
                Title           = task.Title,
                Level           = sectors.Count.ToString(),
                AffectedSectors = string.Join(", ", sectors),
                Description     = task.Description,
                DueDate         = task.DueDate?.ToString(@"dd-MM-yyyy", CultureInfo.InvariantCulture),
                Participants    = task.Participants
            };

            return(this.View(model));
        }
コード例 #4
0
ファイル: TasksController.cs プロジェクト: daqn55/CSharpWeb
        public IHttpResponse Details(int id)
        {
            if (this.User.IsLoggedIn)
            {
                var task = this.Db.Tasks.FirstOrDefault(x => x.Id == id);

                if (task != null)
                {
                    var participants = new List <string>();
                    foreach (var p in task.Participants)
                    {
                        participants.Add(p.User.Username);
                    }

                    var sectors = new List <string>();
                    foreach (var s in task.AffectedSectors)
                    {
                        sectors.Add(s.Sector.ToString());
                    }

                    var viewModel = new DetailsTaskViewModel
                    {
                        Title           = task.Title,
                        DueDate         = task.DueDate.Value.ToString("dd/MM/yyyy"),
                        Level           = task.AffectedSectors.Count,
                        Description     = task.Description,
                        Participants    = string.Join(", ", participants),
                        AffectedSectors = string.Join(", ", sectors)
                    };

                    return(this.View(viewModel));
                }

                return(this.BadRequestError("Invalid Task Id!"));
            }

            return(this.Redirect("/"));
        }