Ejemplo n.º 1
0
        public IHttpActionResult Update(RegistryEditDto dto)
        {
            //Recupero l'entity
            var oResult = _registryService.UpdateRegistry(dto);

            //Se ci sono stati errori, li notifico
            if (oResult.HasErrors())
            {
                Log4NetConfig.ApplicationLog.Warn(string.Format("Errore durante la modifica di un'anagrafica. Cognome: {0}, Nome: {1}",
                                                                dto.Surname, dto.Firstname, oResult.GetValidationErrorsInline(" - ")));
                NHibernateHelper.SessionFactory.GetCurrentSession().Transaction.Rollback();
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, oResult)));
            }

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

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

            //Definisco l'entità
            Registry entity = new Registry();

            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)
                {
                    foreach (var item in dto.HealthRisks)
                    {
                        item.Registry = new RegistryDetailDto {
                            Id = entity.Id
                        };
                        var healthRiskValidation = _healthRiskService.CreateHealthRisk(item);
                        if (healthRiskValidation.HasErrors())
                        {
                            return(healthRiskValidation);
                        }
                    }
                }
            }

            //Creo anche l'utenza di sistema
            if (entity.RegistryType == RegistryType.Paziente)
            {
                UserDto userDto = new UserDto();
                userDto.Email     = entity.Email;
                userDto.Firstname = entity.Firstname;
                userDto.Surname   = entity.Surname;
                userDto.Username  = entity.Email;
                var roles = _roleRepository.Fetch(e => e.Name == "Cliente", null);

                var oResult = _accountService.Register(userDto, roles);

                if (oResult.HasErrors())
                {
                    Log4NetConfig.ApplicationLog.Error(string.Format("Errore durante la creazione dell'utenza di sistema: {0} {1}", userDto.Firstname, userDto.Surname));
                    return(new OperationResult <Guid?>
                    {
                        ReturnedValue = (Guid?)oResult.ReturnedValue,
                        ValidationResults = oResult.ValidationResults
                    });
                }
            }

            //Ritorno i risultati
            return(new OperationResult <Guid?>
            {
                ReturnedValue = entity.Id,
                ValidationResults = vResults
            });
        }
Ejemplo n.º 3
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
            });
        }