public async Task <string> RegisterService(RegisterServiceRequest registerServiceRequest) { var service = new Service { Id = DataUtil.GenerateUniqueId(), Name = registerServiceRequest.ServiceName, ServiceState = ServiceState.Start, IpAddress = registerServiceRequest.IpAddress, LoggerNotifyEnable = registerServiceRequest.LoggerNotifyEnable, HealthCheckNotifyEnable = registerServiceRequest.HealthCheckNotifyEnable, LastCheckedDate = DateTime.UtcNow, RegisteredDate = DateTime.UtcNow, RunningVersion = registerServiceRequest.Version, InstanceNo = await _serviceRepository.GetLastInstanceNoOfService(registerServiceRequest.ServiceName) }; service.ServiceHardwareInfo = new Entities.ServiceHardwareInfo { ServiceId = service.Id, AllocationMemory = registerServiceRequest.ServiceHardwareInfo.MemoryAmount, Id = DataUtil.GenerateUniqueId(), Directory = registerServiceRequest.ServiceHardwareInfo.Directory, MachineName = registerServiceRequest.ServiceHardwareInfo.MachineName, Os = registerServiceRequest.ServiceHardwareInfo.Os, ProcessorCores = registerServiceRequest.ServiceHardwareInfo.ProcessorCores }; service.CalculateRunningTime(); await _serviceRepository.AddAsync(service); return(service.Id); }
public async Task <ServiceResponseModel> CreateService(ServiceRequestModel serviceRequestModel) { var service = _mapper.Map <Service>(serviceRequestModel); var createdService = await _serviceRepository.AddAsync(service); return(_mapper.Map <ServiceResponseModel>(createdService)); }
public async Task <ServiceResponse> SaveAsync(Service service) { try { await _serviceRepository.AddAsync(service); await _unitOfWork.CompleteAsync(); return(new ServiceResponse(service)); } catch (Exception ex) { return(new ServiceResponse($"An error ocurred while saving the Service: {ex.Message}")); } }
public async Task <IActionResult> AddService([FromForm] ServiceDTO request) { try { if (String.IsNullOrEmpty(request.TitleEn)) { return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, "English Title Not Found!")); } else if (String.IsNullOrEmpty(request.TitleAr)) { return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, "Arabic Title Not Found!")); } else if (String.IsNullOrEmpty(request.DescriptionEn)) { return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, "English Description Not Found!")); } else if (String.IsNullOrEmpty(request.DescriptionAr)) { return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, "Arabic Description Not Found!")); } else { var result = await _serviceRepo.AddAsync(request); if (result != null) { return(Ok(result)); } else { return(NoContent()); } } } catch (Exception ex) { return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <string> RegisterService(RegisterServiceModel registerServiceModel) { var service = new Service { Id = DataUtil.GenerateUniqueId(), Name = registerServiceModel.ServiceName, ServiceState = ServiceState.Start, IpAddress = registerServiceModel.IpAddress, ServiceHardwareInfo = registerServiceModel.ServiceHardwareInfo, LoggerNotifyEnable = registerServiceModel.LoggerNotifyEnable, HealthCheckNotifyEnable = registerServiceModel.HealthCheckNotifyEnable, LastCheckedDate = DateTime.UtcNow, RegisteredDate = DateTime.UtcNow, RunningVersion = registerServiceModel.Version, InstanceNo = await _serviceRepository.GetLastInstanceNoOfService(registerServiceModel.ServiceName) }; service.ServiceHardwareInfo.ServiceId = service.Id; service.CalculateRunningTime(); await _serviceRepository.AddAsync(service); return(service.Id); }
public async Task <int> AddServiceAsync(AddServiceDto addServiceDto) { return(await _repository.AddAsync(_converter.AddServiceDtoToService(addServiceDto))); }