Пример #1
0
        public async Task <ResponseApi> Handle(UpdateListAcademicFormationCommand request, CancellationToken cancellationToken)
        {
            try
            {
                int invalidQty = 0;

                foreach (var formation in request.AcademicFormations)
                {
                    formation.Validate();
                    if (formation.Invalid)
                    {
                        invalidQty += 1;
                    }

                    if (invalidQty > 0)
                    {
                        return(new ResponseApi(false, "Something is wrong...", formation.Notifications));
                    }
                }

                List <AcademicFormationViewModel> result = new List <AcademicFormationViewModel>();

                for (int i = 0; i < request.AcademicFormations.Count; i++)
                {
                    AcademicFormation academicFormation = _mapper.Map <AcademicFormation>(await _academicFormationRepository.Get(request.AcademicFormations[i].Id));

                    academicFormation.UpdateFields(_mapper.Map <AcademicFormation>(request.AcademicFormations[i]));
                    await _academicFormationRepository.Update(academicFormation);

                    var updateResult = new AcademicFormationViewModel
                    {
                        Id = academicFormation.Id,
                        InstituitionName = academicFormation.InstituitionName,
                        CourseTitle      = academicFormation.CourseTitle,
                        ConclusionDate   = academicFormation.ConclusionDate,
                        FinalPaperTitle  = academicFormation.FinalPaperTitle,
                        Active           = academicFormation.Active,
                        Excluded         = academicFormation.Excluded,
                        CreationDate     = academicFormation.CreationDate,
                        LastUpdate       = academicFormation.LastUpdate,
                        IdUser           = academicFormation.IdUser
                    };

                    result.Add(updateResult);
                }

                return(new ResponseApi(true, "Academic formation updated sucessfuly", result));
            }
            catch (Exception e)
            {
                return(new ResponseApi(false, "Error...", e));
            }
        }
Пример #2
0
        public async Task <IActionResult> UpdateAcademicFormation([FromBody] UpdateListAcademicFormationCommand updateFormation)
        {
            var result = await _mediator.Send(updateFormation);

            return(Ok(result));
        }