/
RxController.cs
105 lines (94 loc) · 4.35 KB
/
RxController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestTrac.Models;
using TestTrac.Models.ViewModels;
using TestTrac.Models.Repositories;
using TestTrac.Common;
using Elmah;
using TestTrac.Common.Logging.NLog;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using TestTrac.Common.CustomAttributes;
namespace TestTrac.Controllers
{
[NoCache]
public class RxController : Controller
{
//#if DEBUG
//
// GET: /Rx/
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index()
{
return View();
}
[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
[ValidateAntiForgeryToken]
public ActionResult GetDonorStatus(RxUploadDonorViewModel rxUpload)
{
try
{
string partialView = "_RxUploadDonorForm";
if (ModelState.IsValid)
{
IRxUpload rxUploadInfo = new RxUploadRespository();
dynamic rxMessage = rxUploadInfo.VerifyDonor(rxUpload);
if (rxMessage.showUpload == true)
{
partialView = "_RxUploadFileForm";
RxUploadFileViewModel rxUploadFile = new RxUploadFileViewModel();
rxUploadFile.Token = rxMessage.token;
return Json(new { html = Utility.RenderRazorViewToString(this.ControllerContext, partialView, rxUploadFile, this.ViewData, this.TempData), isValid = ModelState.IsValid, rxMessage = rxMessage });
}
else
{
return Json(new { html = Utility.RenderRazorViewToString(this.ControllerContext, partialView, rxUpload, this.ViewData, this.TempData), isValid = ModelState.IsValid, rxMessage = rxMessage });
}
}
else
{
return Json(new { html = Utility.RenderRazorViewToString(this.ControllerContext, partialView, rxUpload, this.ViewData, this.TempData), isValid = ModelState.IsValid, rxMessage = "" });
}
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex); // Send error to ELMAH for logging purposes
Utility.Log(NLogLogger.LogLevel.Error, "Error in GetDonorStatus in RxController", GetType().FullName, ex);
return new HttpStatusCodeResult(400, "Bad Request. Try again. If the problem persists contact the web administrator."); // Bad Request
}
}
[AcceptVerbs(HttpVerbs.Post)]
[ValidateAntiForgeryToken]
public ActionResult UploadRx(RxUploadFileViewModel rxUploadFile)
{
try
{
string partialView = "_RxUploadFileForm";
if (ModelState.IsValid)
{
IRxUpload rxUploadFileData = new RxUploadRespository();
dynamic rxMessage = rxUploadFileData.UploadRx(rxUploadFile);
return Json(new { html = Utility.RenderRazorViewToString(this.ControllerContext, partialView, rxUploadFile, this.ViewData, this.TempData), isValid = ModelState.IsValid, rxMessage = rxMessage });
}
else
{
var errorList = ModelState.Values.SelectMany(m => m.Errors)
.Select(e => e.ErrorMessage)
.ToList();
return Json(new { html = Utility.RenderRazorViewToString(this.ControllerContext, partialView, rxUploadFile, this.ViewData, this.TempData), isValid = ModelState.IsValid, rxMessage = new { showUploadSuccess = false }, rxErrorList = errorList });
}
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex); // Send error to ELMAH for logging purposes
Utility.Log(NLogLogger.LogLevel.Error, "Error in UploadRx in RxController", GetType().FullName, ex);
return new HttpStatusCodeResult(400, "Bad Request. Try again. If the problem persists contact the web administrator."); // Bad Request
}
}
//#endif
}
}