public static AddMajorCodeViewModel Create(IRepositoryWithTypedId<MajorCode, string> majorRepository, MajorCode majorCode) { Check.Require(majorRepository != null, "Repository is required."); var viewModel = new AddMajorCodeViewModel() {MajorCodes = majorRepository.GetAll("Id", true), MajorCode = majorCode, NewMajor = false}; return viewModel; }
unsafe public IrpArrivedViewModel(int index, string driverName, IrpArrivedInfoBase *info) : base(index, driverName, &info->Header) { ProcessId = info->ProcessId; ThreadId = info->ThreadId; MajorCode = info->MajorFunction; switch (MajorCode) { case IrpMajorCode.PNP: MinorCode = ((IrpMinorCodePnp)info->MinorFunction).ToString(); break; case IrpMajorCode.POWER: MinorCode = ((IrpMinorCodePower)info->MinorFunction).ToString(); break; case IrpMajorCode.SYSTEM_CONTROL: MinorCode = ((IrpMinorCodeWmi)info->MinorFunction).ToString(); break; } IrpType = IrpType.Sent; Icon = "/icons/irp-sent.ico"; DriverObject = info->DriverObject.ToInt64(); DeviceObject = info->DeviceObject.ToInt64(); Irp = info->Irp.ToInt64(); if (ProcessId == 4) { ProcessName = "System"; } else { using (var process = OpenProcess(ProcessAccessMask.QueryLimitedInformation, false, ProcessId)) { if (!process.IsInvalid) { int size = _sb.Capacity; if (QueryFullProcessImageName(process, ImageNameType.Normal, _sb, ref size)) { ProcessName = Path.GetFileName(_sb.ToString()); } } } } Details = GetDetails(info); DataSize = info->DataSize; if (DataSize > 0) { Data = new byte[DataSize]; fixed(byte *p = Data) { Buffer.MemoryCopy((byte *)info + info->Header.Size - DataSize, p, DataSize, DataSize); } } Function = MajorCode.ToString() + (MinorCode == null ? null : (" / " + MinorCode)); }
public ActionResult Add(string majorId, string majorCode, string majorName) { ModelState.Clear(); var major = _majorRepository.GetNullableById(!string.IsNullOrEmpty(majorId) ? majorId : majorCode); if (major == null && !string.IsNullOrEmpty(majorCode) && !string.IsNullOrEmpty(majorName)) { major = new MajorCode(majorCode, majorName); } if (major == null) { ModelState.AddModelError("Major", "Invalid major code or missing information."); } else { if (!string.IsNullOrWhiteSpace(majorName)) { major.Name = majorName; } major.TransferValidationMessagesTo(ModelState); if (major.Id.Trim().Length > 4) { ModelState.AddModelError("MajorCode.Id", "Major Code has a max length of 4 characters."); } } //ModelState.AddModelError("Testing", "Always fail validation."); if (ModelState.IsValid) { major.IsActive = true; _majorRepository.EnsurePersistent(major); Message = "Major has been added/activated"; return this.RedirectToAction<MajorCodeController>(a => a.Index()); } var viewModel = AddMajorCodeViewModel.Create(_majorRepository, major); viewModel.NewMajor = string.IsNullOrEmpty(majorId) && !string.IsNullOrWhiteSpace(majorCode); if (viewModel.NewMajor && viewModel.MajorCode == null) { viewModel.MajorCode = new MajorCode(majorCode, majorName); } return View(viewModel); }
private bool ValidateMajorMove(MajorCode majorCode, Ceremony destCeremony, Ceremony origCeremony, out string message) { if (majorCode == null || origCeremony == null || destCeremony == null) { message = "There was an error, validating this move."; return false; } if (destCeremony.Majors.Contains(majorCode)) { message = "Major is already in the selected ceremony."; return false; } // figure out how many students/tickets are getting moved var participations = Repository.OfType<RegistrationParticipation>().Queryable .Where(a => a.Ceremony == origCeremony && a.Major == majorCode).ToList(); message = string.Format("You have requested to move {0} to {1} ceremony. This will move {2} students with {3} tickets leaving {4} available." , majorCode.Name, destCeremony.DateTime.ToString("g"), participations.Count(), participations.Sum(a => a.TotalTickets) , destCeremony.AvailableTickets - participations.Sum(a => a.TotalTickets)); return true; }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionCode"/> struct. /// </summary> /// <param name="major">The major.</param> /// <param name="minor">The minor.</param> public ExceptionCode(MajorCode major, string minor = null) { this.Major = major; this.Minor = minor; }
private static Ceremony GetCeremony(IRepository repository, MajorCode major) { return repository.OfType<Ceremony>().Queryable.FirstOrDefault(x => x.TermCode == TermService.GetCurrent() && x.Majors.Contains(major)); }
private static CeremonyParticipation CreateCeremonyParticipation(int index, bool edit, Student student, MajorCode major, Ceremony ceremony, Registration registration, List<CeremonyParticipation> ceremonyParticipations, IRepository repository, bool admin = false) { if (ceremony != null) { var part = new CeremonyParticipation(); part.Index = index; part.Major = major; part.Ceremony = ceremony; part.Edit = edit; part.NeedsPetition = (student.TotalUnits < ceremony.MinUnits && student.TotalUnits >= ceremony.PetitionThreshold) || (ceremony.TermCode.CanRegister() && !ceremony.TermCode.CanRegister(true)); if (ceremonyParticipations != null) { var existingPart = ceremonyParticipations.FirstOrDefault(a => a.Ceremony == ceremony && a.Major == major); if (existingPart != null) { part.Tickets = existingPart.Tickets; part.Participate = existingPart.Participate; part.Cancel = existingPart.Cancel; part.NeedsPetition = existingPart.NeedsPetition; part.TicketDistributionMethod = existingPart.TicketDistributionMethod; } } if (registration != null) { var regPart = registration.RegistrationParticipations.FirstOrDefault(a => a.Ceremony.Id == ceremony.Id && a.Major.Id == major.Id); if (regPart != null) { part.ParticipationId = regPart.Id; part.Tickets = regPart.NumberTickets; part.Participate = !regPart.Cancelled; part.Cancel = regPart.Cancelled; part.NeedsPetition = false; // registered, don't need to petition part.TicketDistributionMethod = regPart.TicketDistributionMethod; } } if (admin) { // set the college/ceremony lookup values var college = repository.OfType<College>().Queryable.FirstOrDefault(x => x.Display && x.Id == major.College.Id); var ceremonies = repository.OfType<Ceremony>().Queryable.Where(x => x.TermCode == TermService.GetCurrent() && x.Colleges.Contains(college)).ToList(); var majors = ceremonies.SelectMany(x => x.Majors).Where(x => x.IsActive); part.College = college; part.Ceremonies = ceremonies; part.MajorCodes = majors.Where(x => x.College == college && x.ConsolidationMajor == null).OrderBy(x => x.MajorName).ToList(); } else { part.MajorCodes = part.Ceremony.Majors.OrderBy(x => x.MajorName).ToList(); } return part; } return null; }
public static MajorCode MajorCode(int? count) { var rtValue = new MajorCode(); rtValue.Name = "Name" + count.Extra(); rtValue.DisciplineCode = "DisciplineCode" + count.Extra(); return rtValue; }
public CeremonyWithMajor(Ceremony ceremony, MajorCode majorCode) { Ceremony = ceremony; MajorCode = majorCode; }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionCode"/> struct. /// </summary> /// <param name="major">The major.</param> /// <param name="minor">The minor.</param> public ExceptionCode(MajorCode major, string minor = null) { Major = major; Minor = minor; }