示例#1
0
        /// <summary>
        /// Function delete the Form W2 Return to Efile
        /// </summary>
        /// <param name="submissionId">SubmissionId passed to delete the W-2 return</param>
        /// <returns></returns>
        public ActionResult Delete(Guid submissionId)
        {
            var deleteReturnRequest      = new DeleteReturnRequest();
            var deleteReturnResponse     = new FormW2DeleteReturnResponse();
            var deleteReturnResponseJSON = string.Empty;
            var recordIdsString          = string.Empty;

            if (submissionId != null && submissionId != Guid.Empty)
            {
                if (submissionId != null && submissionId != Guid.Empty)
                {
                    deleteReturnRequest.SubmissionId = submissionId;
                    // Getting the RecordIds for SubmissionId
                    var recordIdsFromSession = APISession.GetRecordIdsBySubmissionId(submissionId);
                    deleteReturnRequest.RecordIds = recordIdsFromSession != null ? recordIdsFromSession.RecordIds : null;
                    if (deleteReturnRequest.RecordIds != null && deleteReturnRequest.RecordIds.Count > 0)
                    {
                        recordIdsString = string.Join(",", deleteReturnRequest.RecordIds);
                        using (var client = new PublicAPIClient())
                        {
                            //API URL to Delete Form W-2 Return
                            string requestUri = "FormW2/Delete?SubmissionId=" + submissionId + "&RecordIds=" + recordIdsString;

                            //Delete
                            APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "DELETE");

                            //Get Response
                            var _response = client.DeleteAsync(requestUri).Result;
                            if (_response != null && _response.IsSuccessStatusCode)
                            {
                                //Read Response
                                var createResponse = _response.Content.ReadAsAsync <FormW2DeleteReturnResponse>().Result;
                                if (createResponse != null)
                                {
                                    deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                    deleteReturnResponse     = new JavaScriptSerializer().Deserialize <FormW2DeleteReturnResponse>(deleteReturnResponseJSON);
                                    if (deleteReturnResponse != null && deleteReturnResponse.StatusCode == (int)StatusCode.Success)
                                    {
                                        //Todo Remove Submission and RecordId from session
                                        APISession.DeleteFormW2APIResponse(submissionId);
                                    }
                                }
                            }
                            else
                            {
                                var createResponse = _response.Content.ReadAsAsync <Object>().Result;
                                deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented);
                                deleteReturnResponse     = new JavaScriptSerializer().Deserialize <FormW2DeleteReturnResponse>(deleteReturnResponseJSON);
                            }
                        }
                    }
                }
            }
            return(PartialView(deleteReturnResponse));
        }