public async Task <DeviceChangeRequestModel> AddAsync(DeviceChangeRequestModel model) { if (model == null) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(model.DeviceId)) { throw new Exception("Device id is required"); } if (string.IsNullOrEmpty(model.Email)) { throw new Exception("Email id is required"); } var existingDataModel = _employeeRepository.GetEmployeeByEmail(model.Email); if (existingDataModel == null || existingDataModel.Status != (int)EmployeeStatus.Active) { throw new COHHttpException(HttpStatusCode.NotFound, false, "You are not our registered employee"); } var exist = _changeRequestRepository.IsChangeRequestExist(model.Email, model.DeviceId); if (exist) { throw new COHHttpException(HttpStatusCode.Found, false, "You have already created device change request with this email id"); } var changeRequest = _deviceChangeRequestMapper.ConvertToDataModel(model); changeRequest.Status = (int)ChangeRequestStatus.Pending; changeRequest.RequestedDate = DateTime.UtcNow; changeRequest = await _changeRequestRepository.AddAsync(changeRequest); return(_deviceChangeRequestMapper.ConvertToModel(changeRequest)); }
public async Task <IHttpActionResult> DeviceChangeRequest([FromBody] DeviceChangeRequestModel model) { var employee = await _changeRequestManager.AddAsync(model); return(Ok(employee)); }