public async Task <IHttpActionResult> Activate(HelpRequestActivationModel model)
        {
            var client = _helpRequestResponseService.GetHelpRequestResponseClient(model.HelpRequestResponseId);

            _helpRequestResponseService.Activate(model);

            var newRequest = _helpRequestResponseService.GetClientHelpRequestResponse(client.ClientId);
            var result     = await _notificationService.SendHelpRequestNotification(client.ClientId, newRequest);

            if (result)
            {
                return(Ok());
            }

            return(InternalServerError());
        }
Example #2
0
        public void Activate(HelpRequestActivationModel model)
        {
            var responses = _context.HelpRequestsResponses
                            .Where(hrr => (hrr.HelpRequestId == model.HelpRequestId) && (hrr.IsActive || hrr.Id == model.HelpRequestResponseId))
                            .ToList();

            if (responses == null)
            {
                throw new ArgumentNullException(nameof(responses));
            }

            responses.ForEach(hrr => hrr.IsActive = false);

            responses.FirstOrDefault(hrr => hrr.Id == model.HelpRequestResponseId).IsActive = true;

            _context.SaveChanges();
        }
        public async Task <ActionResult> ResponseActivate(int responseId, int helpRequestId)
        {
            var model = new HelpRequestActivationModel
            {
                HelpRequestId         = helpRequestId,
                HelpRequestResponseId = responseId
            };

            var response = await _httpClientService
                           .SendRequest("api/helprequest/response", HttpMethod.Put, model);

            if (response.IsSuccessStatusCode)
            {
                return(NotificationSuccessResult(Resource.RecordEditSuccess, Url.RouteUrl(HelpRequestsRoutes.Responses, new { model.HelpRequestId })));
            }

            var errorMessage = await _commonService.CheckForValidationErrors(response, Resource.ApplicationErrorText);

            return(NotificationErrorResult(errorMessage, Url.RouteUrl(HelpRequestsRoutes.Responses, new { model.HelpRequestId })));
        }