/// <inheritdoc /> public async Task <Result> Handle(CancelPersonalEventCommand request, CancellationToken cancellationToken) { Maybe <PersonalEvent> maybePersonalEvent = await _personalEventRepository.GetByIdAsync(request.PersonalEventId); if (maybePersonalEvent.HasNoValue) { return(Result.Failure(DomainErrors.PersonalEvent.NotFound)); } PersonalEvent personalEvent = maybePersonalEvent.Value; if (personalEvent.UserId != _userIdentifierProvider.UserId) { return(Result.Failure(DomainErrors.User.InvalidPermissions)); } Result result = personalEvent.Cancel(_dateTime.UtcNow); if (result.IsFailure) { return(result); } await _unitOfWork.SaveChangesAsync(cancellationToken); return(Result.Success()); }
/// <inheritdoc /> public async Task <Result> Handle(CreatePersonalEventCommand request, CancellationToken cancellationToken) { if (request.UserId != _userIdentifierProvider.UserId) { return(Result.Failure(DomainErrors.User.InvalidPermissions)); } if (request.DateTimeUtc <= _dateTime.UtcNow) { return(Result.Failure(DomainErrors.PersonalEvent.DateAndTimeIsInThePast)); } Maybe <User> maybeUser = await _userRepository.GetByIdAsync(request.UserId); if (maybeUser.HasNoValue) { return(Result.Failure(DomainErrors.User.NotFound)); } Maybe <Category> maybeCategory = Category.FromValue(request.CategoryId); if (maybeCategory.HasNoValue) { return(Result.Failure(DomainErrors.Category.NotFound)); } Result <Name> nameResult = Name.Create(request.Name); if (nameResult.IsFailure) { return(Result.Failure(nameResult.Error)); } User user = maybeUser.Value; PersonalEvent personalEvent = user.CreatePersonalEvent(nameResult.Value, maybeCategory.Value, request.DateTimeUtc); _personalEventRepository.Insert(personalEvent); await _unitOfWork.SaveChangesAsync(cancellationToken); return(Result.Success()); }
/// <inheritdoc /> public async Task <Result> Handle(UpdatePersonalEventCommand request, CancellationToken cancellationToken) { if (request.DateTimeUtc <= _dateTime.UtcNow) { return(Result.Failure(DomainErrors.PersonalEvent.DateAndTimeIsInThePast)); } Maybe <PersonalEvent> maybePersonalEvent = await _personalEventRepository.GetByIdAsync(request.PersonalEventId); if (maybePersonalEvent.HasNoValue) { return(Result.Failure(DomainErrors.PersonalEvent.NotFound)); } PersonalEvent personalEvent = maybePersonalEvent.Value; if (personalEvent.UserId != _userIdentifierProvider.UserId) { return(Result.Failure(DomainErrors.User.InvalidPermissions)); } Result <Name> nameResult = Name.Create(request.Name); if (nameResult.IsFailure) { return(Result.Failure(nameResult.Error)); } personalEvent.ChangeName(nameResult.Value); personalEvent.ChangeDateAndTime(request.DateTimeUtc); await _unitOfWork.SaveChangesAsync(cancellationToken); return(Result.Success()); }
/// <summary> /// Initializes a new instance of the <see cref="PersonalEventCreatedDomainEvent"/> class. /// </summary> /// <param name="personalEvent">The personal event.</param> internal PersonalEventCreatedDomainEvent(PersonalEvent personalEvent) => PersonalEvent = personalEvent;
protected override void InternalGenerate() { IColor clrBlack = AppHost.GfxProvider.CreateColor(0x000000); IColor clrBlue = AppHost.GfxProvider.CreateColor(0x0000FF); fTitleFont = fWriter.CreateFont("", 14f, true, false, clrBlack); fChapFont = fWriter.CreateFont("", 12f, true, false, clrBlack); fTextFont = fWriter.CreateFont("", 10f, false, false, clrBlack); //fWriter.AddParagraph(fTitle, fTitleFont, TextAlignment.taLeft); fWriter.AddParagraph(GKUtils.GetNameString(fPerson, true, false), fTitleFont, TextAlignment.taLeft); fWriter.NewLine(); var evList = new List <PersonalEvent>(); GDMIndividualRecord father = null, mother = null; if (fPerson.ChildToFamilyLinks.Count > 0) { GDMFamilyRecord family = fPerson.ChildToFamilyLinks[0].Family; if (fBase.Context.IsRecordAccess(family.Restriction)) { father = family.Husband.Individual; mother = family.Wife.Individual; } } ExtractEvents(EventType.Personal, evList, fPerson); int num2 = fPerson.SpouseToFamilyLinks.Count; for (int j = 0; j < num2; j++) { GDMFamilyRecord family = fPerson.SpouseToFamilyLinks[j].Family; if (!fBase.Context.IsRecordAccess(family.Restriction)) { continue; } ExtractEvents(EventType.Spouse, evList, family); int num3 = family.Children.Count; for (int i = 0; i < num3; i++) { GDMIndividualRecord child = family.Children[i].Individual; GDMCustomEvent evt = child.FindEvent(GEDCOMTagType.BIRT); if (evt != null && evt.GetChronologicalYear() != 0) { evList.Add(new PersonalEvent(EventType.Child, child, evt)); } } } SortHelper.QuickSort(evList, EventsCompare); fWriter.BeginList(); int num4 = evList.Count; for (int i = 0; i < num4; i++) { PersonalEvent evObj = evList[i]; if (!evObj.Date.HasKnownYear()) { continue; } GDMCustomEvent evt = evObj.Event; string st = GKUtils.GetEventName(evt); string dt = GKUtils.GEDCOMEventToDateStr(evt, GlobalOptions.Instance.DefDateFormat, false); if (ShowAges) { int year = evt.GetChronologicalYear(); int age = (evObj.Rec == fPerson) ? GKUtils.GetAge(fPerson, year) : -1; if (age >= 0) { dt += string.Format(" ({0})", age); } } string li = dt + ": " + st + "."; if (evt.Place.StringValue != "") { li = li + " " + LangMan.LS(LSID.LSID_Place) + ": " + evt.Place.StringValue; } fWriter.AddListItem(" " + li, fTextFont); if (evObj.Rec is GDMIndividualRecord) { GDMIndividualRecord iRec = evObj.Rec as GDMIndividualRecord; if (evt.GetTagType() == GEDCOMTagType.BIRT) { if (evObj.Type == EventType.Personal) { if (father != null) { fWriter.AddListItem(" " + " " + LangMan.LS(LSID.LSID_Father) + ": " + GKUtils.GetNameString(father, true, false) + " ", fTextFont); } if (mother != null) { fWriter.AddListItem(" " + " " + LangMan.LS(LSID.LSID_Mother) + ": " + GKUtils.GetNameString(mother, true, false) + " ", fTextFont); } } else if (evObj.Type == EventType.Child) { if (iRec.Sex == GDMSex.svMale) { st = LangMan.LS(LSID.LSID_RK_Son) + ": "; } else { st = LangMan.LS(LSID.LSID_RK_Daughter) + ": "; } st = ConvertHelper.UniformName(st) + GKUtils.GetNameString(iRec, true, false); fWriter.AddListItem(" " + " " + st, fTextFont); } } } else if (evObj.Rec is GDMFamilyRecord) { GDMFamilyRecord famRec = evObj.Rec as GDMFamilyRecord; GDMIndividualRecord sp; string unk; if (fPerson.Sex == GDMSex.svMale) { sp = famRec.Wife.Individual; st = LangMan.LS(LSID.LSID_Wife) + ": "; unk = LangMan.LS(LSID.LSID_UnkFemale); } else { sp = famRec.Husband.Individual; st = LangMan.LS(LSID.LSID_Husband) + ": "; unk = LangMan.LS(LSID.LSID_UnkMale); } string sps; if (sp != null) { sps = st + GKUtils.GetNameString(sp, true, false) /* + GKUtils.GetPedigreeLifeStr(sp, fOptions.PedigreeOptions.Format)*/; } else { sps = st + unk; } fWriter.AddListItem(" " + " " + sps, fTextFont); } } fWriter.EndList(); }
private static int EventsCompare(PersonalEvent item1, PersonalEvent item2) { return(item1.Date.CompareTo(item2.Date)); }
/// <summary> /// Initializes a new instance of the <see cref="PersonalEventDateAndTimeChangedDomainEvent"/> class. /// </summary> /// <param name="personalEvent">The personal event.</param> internal PersonalEventDateAndTimeChangedDomainEvent(PersonalEvent personalEvent) => PersonalEvent = personalEvent;
/// <summary> /// Initializes a new instance of the <see cref="PersonalEventCancelledDomainEvent"/> class. /// </summary> /// <param name="personalEvent">The personal event.</param> internal PersonalEventCancelledDomainEvent(PersonalEvent personalEvent) => PersonalEvent = personalEvent;