protected override IServiceRequestUserInputDto Create(int performingUser, IServiceRequestUserInputDto entity) { using (var context = new PrometheusContext()) { var serviceRequestUserInput = context.ServiceRequestUserInputs.Find(entity.Id); if (serviceRequestUserInput != null) { throw new InvalidOperationException(string.Format("Service Request User Input with ID {0} already exists.", entity.Id)); } var savedInput = context.ServiceRequestUserInputs.Add(ManualMapper.MapDtoToServiceRequestUserInput(entity)); context.SaveChanges(performingUser); return(ManualMapper.MapServiceRequestUserInputToDto(savedInput)); } }
protected override IServiceRequestUserInputDto Update(int performingUser, IServiceRequestUserInputDto userInputDto) { using (var context = new PrometheusContext()) { if (!context.ServiceRequestUserInputs.Any(x => x.Id == userInputDto.Id)) { throw new InvalidOperationException(string.Format("Service Request User Input with ID {0} cannot be updated since it does not exist.", userInputDto.Id)); } var updated = ManualMapper.MapDtoToServiceRequestUserInput(userInputDto); context.ServiceRequestUserInputs.Attach(updated); context.Entry(updated).State = EntityState.Modified; context.SaveChanges(performingUser); return(ManualMapper.MapServiceRequestUserInputToDto(updated)); } }