Esempio n. 1
0
        public IHttpActionResult Update(HealthRiskEditDto dto)
        {
            //Recupero l'entity
            var oResult = _healthRiskService.UpdateHealthRisk(dto);

            //Se ci sono stati errori, li notifico
            if (oResult.HasErrors())
            {
                Log4NetConfig.ApplicationLog.Warn(string.Format("Errore durante la creazione di un health risk. Type: {0}, Level: {1}",
                                                                dto.Type, dto.Level, oResult.GetValidationErrorsInline(" - ")));
                NHibernateHelper.SessionFactory.GetCurrentSession().Transaction.Rollback();
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, oResult)));
            }

            //Ritorno i risultati
            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK)));
        }
Esempio n. 2
0
        public OperationResult <Guid?> UpdateRegistry(RegistryEditDto dto)
        {
            //Validazione argomenti
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }
            if (!dto.Id.HasValue)
            {
                throw new ArgumentNullException(nameof(dto.Id));
            }

            //Dichiaro la lista di risultati di ritorno
            IList <ValidationResult> vResults = new List <ValidationResult>();

            //Definisco l'entità
            Registry entity = _registryRepository.Load(dto.Id);

            entity.Firstname                = dto.Firstname;
            entity.Surname                  = dto.Surname;
            entity.RegistryType             = dto.RegistryType;
            entity.Sex                      = dto.Sex;
            entity.BirthDate                = dto.BirthDate;
            entity.BirthPlace               = dto.BirthPlace;
            entity.DomicilePlace            = dto.DomicilePlace;
            entity.DomicilePlaceAddress     = dto.DomicilePlaceAddress;
            entity.DomicilePlaceCap         = dto.DomicilePlaceCap;
            entity.MunicipalityPlace        = dto.MunicipalityPlace;
            entity.MunicipalityPlaceAddress = dto.MunicipalityPlaceAddress;
            entity.MunicipalityPlaceCap     = dto.MunicipalityPlaceCap;
            entity.Email                    = dto.Email;
            entity.MobilePhone              = dto.MobilePhone;
            entity.Phone                    = dto.Phone;
            entity.RegionalMedicalCode      = dto.RegionalMedicalCode;
            entity.Latitude                 = dto.Latitude;
            entity.Longitude                = dto.Longitude;
            entity.Allergy                  = dto.Allergy;
            entity.Intollerance             = dto.Intollerance;
            entity.BloodGroup               = dto.BloodGroup;
            entity.Diagnosis                = dto.Diagnosis;
            entity.PreviousIllnesses        = dto.PreviousIllnesses;
            entity.NextMedicalHistory       = dto.NextMedicalHistory;
            entity.RemoteAnamnesis          = dto.RemoteAnamnesis;
            entity.Diet                     = dto.Diet;
            entity.PathologiesInProgress    = dto.PathologiesInProgress;
            entity.Note                     = dto.Note;
            entity.Weight                   = dto.Weight;
            entity.Height                   = dto.Height;
            entity.LifeStyle                = dto.LifeStyle;

            if (string.IsNullOrWhiteSpace(entity.MunicipalityPlaceAddress))
            {
                entity.Latitude  = null;
                entity.Longitude = null;
            }


            //Eseguo la validazione logica
            vResults = ValidateEntity(entity);

            if (!vResults.Any())
            {
                //Salvataggio su db
                _registryRepository.Save(entity);

                if (dto.HealthRisks != null)
                {
                    if (entity.HealthRisks == null)
                    {
                        entity.HealthRisks = new List <HealthRisk>();
                    }

                    entity.HealthRisks.Clear();
                    foreach (var item in dto.HealthRisks)
                    {
                        item.Registry = new RegistryDetailDto {
                            Id = entity.Id
                        };

                        var healthRiskValidation = item.Id.HasValue ?
                                                   _healthRiskService.UpdateHealthRisk(item) :
                                                   _healthRiskService.CreateHealthRisk(item);

                        if (healthRiskValidation.HasErrors())
                        {
                            return(healthRiskValidation);
                        }

                        HealthRisk healthRisk = _healthRiskRepository.Load(healthRiskValidation.ReturnedValue);
                        entity.HealthRisks.Add(healthRisk);
                    }
                }
            }

            //Ritorno i risultati
            return(new OperationResult <Guid?>
            {
                ReturnedValue = entity.Id,
                ValidationResults = vResults
            });
        }