public static OspedaleViewModel ToOspedaleViewModel(this Ospedale ospedale)
 {
     return(new OspedaleViewModel
     {
         Id = ospedale.Id,
         Clinica = ospedale.Clinica,
         Comune = ospedale.Comune,
         Latitudine = ospedale.Latitudine,
         Longitudine = ospedale.Longitudine
     });
 }
Exemplo n.º 2
0
        public async Task DeleteOspedaleAsync(OspedaleDeleteInputModel inputModel)
        {
            Ospedale ospedale = await dbContext.Ospedali.FindAsync(inputModel.Id);

            if (ospedale == null)
            {
                throw new OspedaleNotFoundException(inputModel.Id);
            }

            dbContext.Remove(ospedale);
            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task <OspedaleDetailViewModel> CreateOspedaleAsync(OspedaleCreateInputModel inputModel)
        {
            var ospedale = new Ospedale();

            ospedale.ChangeClinica(inputModel.Clinica);
            ospedale.ChangeComune(inputModel.Comune);
            ospedale.ChangeLatitudine(inputModel.Latitudine);
            ospedale.ChangeLongitudine(inputModel.Longitudine);

            dbContext.Add(ospedale);
            await dbContext.SaveChangesAsync();

            return(ospedale.ToOspedaleDetailViewModel());
        }
Exemplo n.º 4
0
        public async Task <OspedaleDetailViewModel> EditOspedaleAsync(OspedaleEditInputModel inputModel)
        {
            Ospedale ospedale = await dbContext.Ospedali.FindAsync(inputModel.Id);

            if (ospedale == null)
            {
                logger.LogWarning("Ospedale {id} non trovato", inputModel.Id);
                throw new OspedaleNotFoundException(inputModel.Id);
            }

            ospedale.ChangeClinica(inputModel.Clinica);
            ospedale.ChangeComune(inputModel.Comune);
            ospedale.ChangeLatitudine(inputModel.Latitudine);
            ospedale.ChangeLongitudine(inputModel.Longitudine);

            await dbContext.SaveChangesAsync();

            return(ospedale.ToOspedaleDetailViewModel());
        }