public async Task <IActionResult> Add([FromBody] AddChildCommand command) { Child child = await mediator.Send(command); var result = new { ChildId = child.Id, Name = child.GetName().Text, BirthDate = child.GetBirthDate().Value }; return(CreatedAtRoute("GetParent", new { id = child.Id, schoolId = command.SchoolId }, result)); }
private async void AddChild(Child child) { if (!child.IsValid()) { MessageBox.Show("Не все поля заполнены/пункты выбраны", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var now = DateTime.Now; if (ChildAdditionDate > now) { MessageBox.Show("Ввод будущей даты добавления запрещён", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (child.BirthDate > ChildAdditionDate) { MessageBox.Show("Дата рождения должна быть меньше даты добавления", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (SelectedOther == null && SelectedMother == null && SelectedFather == null) { MessageBox.Show("Должен быть выбран хотя бы один из родителей либо иной представитель", "Некорректный выбор", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (BroughtParent == Parents.Father && SelectedFather == null || BroughtParent == Parents.Mother && SelectedMother == null || BroughtParent == Parents.Other && SelectedOther == null) { MessageBox.Show("Выберите существующего родителя"); return; } AddChildCommand.NotifyCanExecute(false); ParentChild broghtParent = null; EnterChild enterChild = null; bool needAddPayments = StartedToPayFromAdditionDate; await Task.Run(() => { string imageFileName = null; try { if (_imageUri != null) { var savePath = Path.Combine(Settings.AppFilePaths.ChildImages, CommonHelper.GetUniqueString()); imageFileName = ImageUtil.SaveImage(_imageUri, savePath); child.Person.PhotoPath = Path.GetFileName(imageFileName); } // groups and tarifs (in OnLoaded) are from other context child.GroupId = child.Group.Id; child.Group = null; child.TarifId = child.Tarif.Id; enterChild = new EnterChild { Child = child, EnterDate = ChildAdditionDate }; child.LastEnterChild = enterChild; var context = new KindergartenContext(); if (needAddPayments) { // to no debt range add if (now.Year != ChildAdditionDate.Year && now.Month != ChildAdditionDate.Month) { // 1) the first fictitious payment for start range context.MonthlyPayments.Add(new MonthlyPayment { ChildId = child.Id, PaymentDate = ChildAdditionDate, MoneyPaymentByTarif = 0, // 0 - because to make no debt }); } // 2) the second fictitious payment for end range context.MonthlyPayments.Add(new MonthlyPayment { ChildId = child.Id, PaymentDate = now, MoneyPaymentByTarif = child.Tarif.MonthlyPayment, DebtAfterPaying = InitialDebt, }); } child.Tarif = null; context.EnterChildren.Add(enterChild); if (SelectedFather != null) { var parentChild = new ParentChild { Child = child, ParentId = SelectedFather.Id, ParentType = Parents.Father }; context.ParentChildren.Add(parentChild); if (BroughtParent == Parents.Father) { broghtParent = parentChild; } } if (SelectedMother != null) { var parentChild = new ParentChild { Child = child, ParentId = SelectedMother.Id, ParentType = Parents.Mother }; context.ParentChildren.Add(parentChild); if (BroughtParent == Parents.Mother) { broghtParent = parentChild; } } if (SelectedOther != null) { var parentChild = new ParentChild { Child = child, ParentId = SelectedOther.Id, ParentType = Parents.Other, ParentTypeText = OtherParentText }; context.ParentChildren.Add(parentChild); if (BroughtParent == Parents.Other) { broghtParent = parentChild; } } context.SaveChanges(); App.Logger.Debug("Child added"); } catch { if (imageFileName != null) { File.Delete(imageFileName); } throw; } }); Pipe.SetParameter("saved_child_result", child); Pipe.SetParameter("brought_parent", broghtParent); Pipe.SetParameter("enter", enterChild); // ReSharper disable once RedundantExplicitArraySize var parents = new ParentChild[3] { new ParentChild { Parent = SelectedFather, ParentType = Parents.Father }, new ParentChild { Parent = SelectedMother, ParentType = Parents.Mother }, new ParentChild { Parent = SelectedOther, ParentType = Parents.Other } }; Pipe.SetParameter("parents", parents); AddChildCommand.NotifyCanExecute(true); Finish(); }
public Task PublishExternalEvt(string evt, string casePlanInstanceId, string casePlanElementInstanceId, Dictionary <string, string> parameters, CancellationToken token) { IBaseRequest request = null; switch (evt) { case CMMNConstants.ExternalTransitionNames.AddChild: request = new AddChildCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.Close: request = new CloseCommand(casePlanInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.Complete: request = new CompleteCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.Disable: request = new DisableCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.Occur: request = new OccurCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.Reactivate: request = new ReactivateCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.Reenable: request = new ReenableCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.Resume: request = new ResumeCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.Suspend: request = new SuspendCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.Terminate: request = new TerminateCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; case CMMNConstants.ExternalTransitionNames.ManualStart: request = new ActivateCommand(casePlanInstanceId, casePlanElementInstanceId) { Parameters = parameters }; break; } return(_mediator.Send(request, token)); }