Guest User

Untitled

a guest
Nov 23rd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.27 KB | None | 0 0
  1. [HttpPost]
  2. [ValidateAntiForgeryToken]
  3. public ActionResult Create([Bind(Include = "RequestTestID,PatientID,TestID,DocName,AccountTypeID,TotalPrice,Tests.UnitPrice,AccountTypes.Value,RequestDate")] RequestTest requestTest)
  4. {
  5. var model = new RequestTest();
  6. model.TotalPrice = Convert.ToInt32(requestTest.Tests.UnitPrice * requestTest.AccountTypes.Value);
  7. if (ModelState.IsValid)
  8. {
  9.  
  10. db.RequestTests.Add(model);
  11. db.RequestTests.Add(requestTest);
  12. db.SaveChanges();
  13. return RedirectToAction("Index");
  14. }
  15.  
  16. ViewBag.AccountTypeID = new SelectList(db.AccountTypes, "AccountTypeID", "AcctTypeName", requestTest.AccountTypeID);
  17. ViewBag.PatientID = new SelectList(db.Patients, "ID", "LastName", requestTest.PatientID);
  18. ViewBag.TestID = new SelectList(db.Tests, "TestID", "TestInvestigation", requestTest.TestID);
  19. return View(requestTest);
  20. }`
  21. **Model** ` public class Patient
  22. {
  23. [Display(Name = "Patient Id")]
  24. public int ID { get; set; }
  25.  
  26. [Required]
  27. [Display(Name = "Last Name")]
  28. public string LastName { get; set; }
  29.  
  30. [Required]
  31. [Display(Name = "First Name")]
  32. public string FirstName { get; set; }
  33.  
  34. [Display(Name = "Other Names")]
  35. public string OtherNames { get; set; }
  36.  
  37. [Required]
  38. [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
  39. [Display(Name = "Date of Birth")]
  40. public DateTime DoB { get; set; }
  41.  
  42. [Required]
  43. public string Sex { get; set; }
  44.  
  45. [Display(Name = "Phone Number")]
  46. [StringLength(12, MinimumLength = 10)]
  47. [DataType(DataType.PhoneNumber)]
  48. public string PhoneNo { get; set; }
  49.  
  50. [EmailAddress]
  51. [Display(Name = "Email Address")]
  52. public string EmailAddress { get; set; }
  53. [Display(Name = "Address")]
  54. public string Address { get; set; }
  55. public string City { get; set; }
  56. public virtual ICollection<RequestTest> RequestTestes { get; set; }
  57. public int HospitalNo { get; set; }
  58.  
  59. //[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
  60. private DateTime? _EnrollmentDate;
  61. public DateTime? EnrollmentDate { get { return _EnrollmentDate; } set { _EnrollmentDate = DateTime.Now.Date; } }
  62.  
  63. ////public virtual JntPatienttest PatientId { get; set; }
  64.  
  65. }
  66.  
  67. public class RequestTest
  68. {
  69. public int RequestTestID { get; set; }
  70. public int PatientID { get; set; }
  71. public int TestID { get; set; }
  72. public string DocName { get; set; }
  73.  
  74. public int AccountTypeID { get; set; }
  75.  
  76.  
  77. //private decimal _TotalPrice;
  78.  
  79. //public decimal TotalPrice { get { return Add(Tests.UnitPrice, AccountTypes.Value); } set { this._TotalPrice = value; } }
  80. public int TotalPrice { get; set; }
  81. //[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
  82.  
  83.  
  84. [Display(Name = "Request date")]
  85. private DateTime? _RequestDate;
  86. public DateTime? RequestDate { get { return _RequestDate; } set { _RequestDate = DateTime.Now.Date; } }
  87. public virtual Patient Patients { get; set; }
  88. public virtual Test Tests { get; set; }
  89.  
  90. public virtual AccountType AccountTypes { get; set; }
  91.  
  92. public static decimal Add(decimal a, decimal b)
  93. {
  94. return a * b;
  95. }
  96.  
  97. }
  98. public class Test
  99. {
  100. [DatabaseGenerated(DatabaseGeneratedOption.None)]
  101. [Display(Name = "Test Id")]
  102. public int TestID { get; set; }
  103.  
  104. [Display(Name = "Test Name")]
  105. public string TestInvestigation { get; set; }
  106.  
  107. public string TestCat { get; set; }
  108.  
  109. public decimal UnitPrice { get; set; }
  110.  
  111. public string Material { get; set; }
  112.  
  113. public string BottleType { get; set; }
  114.  
  115. public bool Active { get; set; }
  116.  
  117. public int Scode { get; set; }
  118.  
  119. public string Status { get; set; }
  120.  
  121. public int Bt { get; set; }
  122. public virtual ICollection<RequestTest> RequestTestes { get; set; }
  123.  
  124. }
  125.  
  126. public class AccountType
  127. {
  128. //[ForeignKey("RequestTestID")]
  129. [Key]
  130. public int AccountTypeID { get; set; }
  131.  
  132. public string AcctTypeName { get; set; }
  133.  
  134. public decimal Value { get; set; }
  135.  
  136. //private decimal _Regular;
  137. //public decimal Regular { get { return _Regular; } set { _Regular = 2; } }
  138. //public decimal Vip { get; set; }
  139. //public decimal Nhis { get; set; }
  140. //public decimal Retenanship { get; set; }
  141. //public decimal Ihvn { get; set; }
  142. //public decimal Pedriatics { get; set; }
  143. //public decimal BloodBank { get; set; }
  144. //public decimal Emergency { get; set; }
  145. //public decimal StaffAccount { get; set; }
  146.  
  147. public virtual ICollection<RequestTest> RequestTestes { get; set; }
  148.  
  149. }` **View**`
  150. @using (Html.BeginForm())
  151. {
  152.  
  153. <form method="post" action="~/Views/RequestTests/Create.cshtml">
  154. @Html.AntiForgeryToken()
  155.  
  156. <div class="form-horizontal">
  157. <h4>RequestTest</h4>
  158. <hr />
  159. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  160. <div class="form-group">
  161. @Html.LabelFor(model => model.PatientID, "PatientID", htmlAttributes: new { @class = "control-label col-md-2" })
  162. <div class="col-md-10">
  163. @Html.DropDownList("PatientID", null, htmlAttributes: new { @class = "form-control" })
  164. @Html.ValidationMessageFor(model => model.PatientID, "", new { @class = "text-danger" })
  165. </div>
  166. </div>
  167.  
  168. <div class="form-group">
  169. @Html.LabelFor(model => model.TestID, "TestID", htmlAttributes: new { @class = "control-label col-md-2" })
  170. <div class="col-md-10">
  171. @Html.DropDownList("TestID", null, htmlAttributes: new { @class = "form-control" })
  172. @Html.ValidationMessageFor(model => model.TestID, "", new { @class = "text-danger" })
  173. </div>
  174. </div>
  175.  
  176. <div class="form-group">
  177. @Html.LabelFor(model => model.DocName, htmlAttributes: new { @class = "control-label col-md-2" })
  178. <div class="col-md-10">
  179. @Html.EditorFor(model => model.DocName, new { htmlAttributes = new { @class = "form-control" } })
  180. @Html.ValidationMessageFor(model => model.DocName, "", new { @class = "text-danger" })
  181. </div>
  182. </div>
  183.  
  184. <div class="form-group">
  185. @Html.LabelFor(model => model.AccountTypeID, "AccountTypeID", htmlAttributes: new { @class = "control-label col-md-2" })
  186. <div class="col-md-10">
  187. @Html.DropDownList("AccountTypeID", null, htmlAttributes: new { @class = "form-control" })
  188. @Html.ValidationMessageFor(model => model.AccountTypeID, "", new { @class = "text-danger" })
  189. </div>
  190. </div>
  191.  
  192. @*<div class="form-group">
  193. @Html.LabelFor(model => model.TotalPrice, htmlAttributes: new { @class = "control-label col-md-2" })
  194. <div class="col-md-10">
  195. @Html.EditorFor(model => model.TotalPrice, new { htmlAttributes = new { @class = "form-control" } })
  196. @Html.ValidationMessageFor(model => model.TotalPrice, "", new { @class = "text-danger" })
  197. </div>
  198. </div>*@
  199.  
  200. <div class="form-group">
  201. @Html.LabelFor(model => model.RequestDate, htmlAttributes: new { @class = "control-label col-md-2" })
  202. <div class="col-md-10">
  203. @Html.EditorFor(model => model.RequestDate, new { htmlAttributes = new { @class = "form-control" } })
  204. @Html.ValidationMessageFor(model => model.RequestDate, "", new { @class = "text-danger" })
  205. </div>
  206. </div>
  207.  
  208. <div class="form-group">
  209. <div class="col-md-offset-2 col-md-10">
  210. <input type="submit" value="Create" class="btn btn-default" />
  211. </div>
  212. </div>
  213. </div>
  214.  
  215. </form>
  216. }`
Add Comment
Please, Sign In to add comment