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()); }
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()); }