コード例 #1
0
        public void UpdateForContentItem(IContent item, TeamEditViewModel model)
        {
            var teamPart = item.As <TeamPart>();

            teamPart.CupId = model.CupId;
            teamPart.Name  = model.Name;

            var oldAttendees = _teamAttendeeService.GetByTeam(teamPart.Id).ToList();

            // Make sure this is never null
            if (model.TeamAttendees == null)
            {
                model.TeamAttendees = new List <TeamAttendeeEditViewModel>();
            }

            foreach (var attendee in oldAttendees)
            {
                var attendeeModel = model.TeamAttendees.SingleOrDefault(m => m.Id == attendee.Id);

                if (attendeeModel != null)
                {
                    // Update existing attendees
                    attendee.AttendeePartRecord = attendeeModel.AttendeeId.HasValue
                        ? _attendeeService.Get(attendeeModel.AttendeeId.Value).Record
                        : null;
                }
                else
                {
                    // Delete the attendees that no longer exist
                    _teamAttendeeService.Delete(attendee);
                }
            }

            // Add the new attendees
            foreach (var attendee in from attendee in model.TeamAttendees
                     let oldAttendee = oldAttendees.SingleOrDefault(m => m.Id == attendee.Id)
                                       where oldAttendee == null
                                       select attendee)
            {
                _teamAttendeeService.Create(
                    new TeamAttendeeRecord {
                    TeamPartRecord     = teamPart.Record,
                    Id                 = attendee.Id,
                    AttendeePartRecord = attendee.AttendeeId.HasValue
                            ? _attendeeService.Get(attendee.AttendeeId.Value).Record
                            : null
                });
            }
        }
コード例 #2
0
 /// <summary>
 /// Add a team order to the list
 /// </summary>
 /// <returns>TeamOrder view</returns>
 public ActionResult AddTeamAttendee()
 {
     return(PartialView("EditorTemplates/TeamAttendeeEditViewModel", new TeamAttendeeEditViewModel()
     {
         Attendees = _attendeeService.Get()
     }));
 }
コード例 #3
0
        public ActionResult Index(PagerParameters pagerParameters)
        {
            var attendeesProjection = from attendee in _attendeeService.Get()
                                      select Shape.Attendee
                                      (
                Id : attendee.Id,
                FirstName : attendee.FirstName,
                LastName : attendee.LastName
                                      );

            var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters.Page, pagerParameters.PageSize);

            var model = new DynamicIndexViewModel(
                attendeesProjection.Skip(pager.GetStartIndex()).Take(pager.PageSize),
                Shape.Pager(pager).TotalItemCount(_attendeeService.Count()));

            return(View(model));
        }
コード例 #4
0
        private TeamEditViewModel BuildEditorViewModel(TeamPart part)
        {
            var attendees = _attendeeService.Get();
            var cups      = _cupService.Get();

            var teamAttendees = part.TeamMates.Select(teamMate => new TeamAttendeeEditViewModel {
                Id         = teamMate.Id,
                AttendeeId = teamMate.AttendeePartRecord.Id,
                Attendees  = attendees
            }).ToList();

            return(new TeamEditViewModel {
                Cups = cups,
                CupId = part.CupId,
                Name = part.Name,
                TeamAttendees = teamAttendees
            });
        }
コード例 #5
0
        /// <summary>
        /// Creates and Excel spreadsheet with the name of the atteneee
        /// and a list of all workshops he/she has attended with hours.
        /// </summary>
        /// <param name="attendeeId"></param>
        /// <returns></returns>
        public byte[] AttendeeWorkshopHours(int attendeeId)
        {
            // Get attendee and hours from db
            var attendee      = _attendeeService.Get(attendeeId);
            var workshopHours = _attendeeHourService.GetAttendeeWorkshopHours(attendeeId);

            using (var ms = new MemoryStream())
            {
                using (var package = new ExcelPackage(ms))
                {
                    // Create a new worksheet
                    var worksheet = package.Workbook.Worksheets.Add("Sheet 1");

                    // Attendee name and ID centered across columns A, B and C
                    worksheet.Cells["A1"].Value = attendee.FullName;
                    worksheet.Cells["A2"].Value = attendee.CertId;
                    worksheet.Cells["A1:C1"].Style.HorizontalAlignment =
                        OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
                    worksheet.Cells["A1:C1"].Merge                     = true;
                    worksheet.Cells["A1:C1"].Style.Font.Size           = 18;
                    worksheet.Cells["A2:C2"].Style.HorizontalAlignment =
                        OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
                    worksheet.Cells["A2:C2"].Merge = true;

                    var row = 4;
                    // Headings on row 4
                    worksheet.Cells[row, 1].Value           = "Workshop";
                    worksheet.Cells[row, 1].Style.Font.Bold = true;
                    worksheet.Cells[row, 2].Value           = "Date";
                    worksheet.Cells[row, 2].Style.Font.Bold = true;
                    worksheet.Cells[row, 3].Value           = "PD Hours";
                    worksheet.Cells[row, 3].Style.Font.Bold = true;

                    // Set column widths
                    worksheet.Column(1).Width = 55;
                    worksheet.Column(2).Width = 12;
                    worksheet.Column(3).Width = 10;



                    // Loop through the workshops
                    row++;
                    var col = 1;
                    foreach (var workshop in workshopHours)
                    {
                        // Reset col to 1
                        col = 1;
                        worksheet.Cells[row, col].Value = workshop.WorkshopName;

                        col++;
                        worksheet.Cells[row, col].Value = workshop.TrainingDate.ToShortDateString();

                        col++;
                        worksheet.Cells[row, col].Value = workshop.PDHours;

                        // Update row
                        row++;
                    }

                    // Set number format of PD hours column to two decimals
                    worksheet.Column(3).Style.Numberformat.Format = "0.00";

                    // Sum the hours
                    worksheet.Cells[row, col].Formula = $"SUM(C4:C{row-1})";
                    worksheet.Cells[row, col].Style.Border.Bottom.Style =
                        OfficeOpenXml.Style.ExcelBorderStyle.Double;
                    worksheet.Cells[row, col].Style.Border.Top.Style =
                        OfficeOpenXml.Style.ExcelBorderStyle.Medium;
                    worksheet.Cells[row, 1].Value           = "Total";
                    worksheet.Cells[row, 1].Style.Font.Bold = true;

                    // Return the Excel file data. All data is in memory
                    return(package.GetAsByteArray());
                }
            }
        }