protected override IServiceOptionDto Create(int performingUserId, IServiceOptionDto entity) { using (var context = new PrometheusContext()) { var serviceOption = context.ServiceOptions.Find(entity.Id); if (serviceOption != null) { throw new InvalidOperationException(string.Format("Service Option with ID {0} already exists.", entity.Id)); } var savedOption = context.ServiceOptions.Add(ManualMapper.MapDtoToServiceOption(entity)); context.SaveChanges(performingUserId); return(ManualMapper.MapServiceOptionToDto(savedOption)); } }
protected override IServiceOptionDto Update(int performingUserId, IServiceOptionDto entity) { using (var context = new PrometheusContext()) { if (!context.ServiceOptions.Any(x => x.Id == entity.Id)) { throw new InvalidOperationException(string.Format("Service Option with ID {0} cannot be updated since it does not exist.", entity.Id)); } var updatedOption = ManualMapper.MapDtoToServiceOption(entity); context.ServiceOptions.Attach(updatedOption); context.Entry(updatedOption).State = EntityState.Modified; context.SaveChanges(performingUserId); return(ManualMapper.MapServiceOptionToDto(updatedOption)); } }