public ActionResult SendMessageResponse(OpenedMessageViewModel omVM) { if (!Request.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } else { if (ModelState.IsValid) { //send a request on the main server and await for the response long curentUserId = User.Identity.GetUserId <long>(); DTOHelper dtoHlp = new DTOHelper(); MyRemoteServices.AgentEndpointPortClient aepc = new MyRemoteServices.AgentEndpointPortClient(); MyRemoteServices.sendMessageRequest smRequest = dtoHlp.GetMessageRequest(omVM, curentUserId); MyRemoteServices.sendMessageResponse smResponse = aepc.sendMessage(smRequest); if (smResponse.responseWrapper.success) { //save localy using (var ctx = new ApplicationDbContext()) { ResponseMessage respMsg = new ResponseMessage { Content = omVM.ResponseContent, MainServerId = (long)smResponse.responseWrapper.responseBody }; ctx.ResponseMessages.Add(respMsg); Message msg = ctx.Messages.FirstOrDefault(x => x.Id == omVM.Id); msg.HasResponse = true; msg.ResponseMessage = respMsg; ctx.SaveChanges(); } } else { //some error happened, retry TempData["error"] = smResponse.responseWrapper.message; return(RedirectToAction("OpenMessage", "Agent", new { messageId = omVM.Id })); } TempData["success"] = "Successfully sent the response message to: " + omVM.SenderUserName; return(RedirectToAction("OpenMessage", "Agent", new { messageId = omVM.Id })); } else { //invalid VM exception TempData["error"] = "Some form atributes are incorrect"; return(RedirectToAction("OpenMessage", "Agent", new { messageId = omVM.Id })); } } }