public async Task <IActionResult> UpdateServiceRequestForApprove(int id) { var result = await _repository.GetServiceRequestDetails(id); if (result == null) { return(NotFound()); } if (_repository.IsServiceProviderAlreadyOnRide(result.Service.ServiceProviderId)) { return(BadRequest("Service Provider is already on ride. At this moment this service provider can not approve ride request")); } result.IsPending = false; result.IsApproved = true; await _unitOfWork.CompleteAsync(); //Start Sending notification after approve a Service request var approvedNotification = new NotificationInformation(); approvedNotification.DeviceInformations = await _userDeviceInfoRepository.GetUserDeviceInformationsAsync(result.ApplicationUser.Id); approvedNotification.NotiTitle = "Knarr"; approvedNotification.NotiMessage = "Ride Request Approved"; await _fireBaseServiceClient.SendNotification(approvedNotification); //End Sending notification after approve a Service request return(Ok(result)); }
public async Task <IActionResult> CreateUserDeviceInformation([FromBody] SaveUserDeviceInformationResources resource) { IActionResult result; if (ModelState.IsValid) { resource.UserId = await GetUserId(); var deviceInformationList = await _repository.GetUserDeviceInformationsAsync(resource.UserId); var status = true; var userDeviceInformationses = deviceInformationList as UserDeviceInformations[] ?? deviceInformationList.ToArray(); if (userDeviceInformationses.Any()) { if (userDeviceInformationses.Any(deviceInfo => deviceInfo.UserId == resource.UserId && deviceInfo.DeviceId == resource.DeviceId)) { status = false; } } if (status) { var details = _mapper.Map <SaveUserDeviceInformationResources, UserDeviceInformations>(resource); _repository.Add(details); await _unitOfWork.CompleteAsync(); var saveUserDeviceInformationResources = _mapper.Map(details, resource); result = Ok(saveUserDeviceInformationResources); } else { result = Ok("Information previously stored. No need to store anymore."); } } else { result = BadRequest(ModelState); } return(result); }