Praveen Kumar

Praveen Kumar

  • NA
  • 235
  • 20.4k

Value cannot be null" Parameter Name:source

Jul 15 2020 2:11 AM
Hi
 
I am getting error "Value cannot be null" Parameter Name:source"
 
 
 
Addaccount.cshtml
  1. @model Redi2.RMIM.Web.Areas.AccountSetup.Models.AccountDetailViewModel  
  2. @section DevExtremeBundles  
  3. {  
  4. @Styles.Render("~/Content/DevExtremeBundle")  
  5. @Scripts.Render("~/Scripts/DevExtremeBundle")  
  6. }  
  7. <div class="modal-header">  
  8. <h4 class="modal-title" id="myModalLabel">Account Details</h4>  
  9. <button type="button" class="close" data-dismiss="modal" aria-label="Close">  
  10. <span aria-hidden="true">×</span>  
  11. </button>  
  12. </div>  
  13. @using (Html.BeginForm("AddAccountModal""Manage"new { Area = "Client" }, FormMethod.Post, new { @class = "form-horizontal", id = "addAccountModalForm" }))  
  14. {  
  15. @Html.AntiForgeryToken()  
  16. @Html.ValidationSummary(true""new { @class = "text-danger" })  
  17. @Html.HiddenFor(model => model.Account.Id)  
  18. @Html.HiddenFor(model => model.Client.ParentId)  
  19. <div class="modal-body">  
  20. <div class="box box-solid">  
  21. <div class="box-header">  
  22. <h5 class="box-title">Account Infomation:</h5>  
  23. </div>  
  24. <div class="box-body">  
  25. <div class="form-group row">  
  26. <!-- /.col-lg-6 -->  
  27. @Html.LabelFor(model => model.Account.Name, new { @class = "col-sm-5 control-label", @required = "required" })  
  28. <div class="col-sm-5">  
  29. @Html.EditorFor(model => model.Account.Name)  
  30. @Html.ValidationMessageFor(model => model.Account.Name, ""new { @class = "text-danger" })  
  31. </div>  
  32. </div>  
  33. <div class="form-group row">  
  34. @Html.LabelFor(model => model.Account.Number, new { @class = "col-sm-5 control-label", @required = "required" })  
  35. <div class="col-sm-5">  
  36. @Html.EditorFor(model => model.Account.Number)  
  37. @Html.ValidationMessageFor(model => model.Account.Number, ""new { @class = "text-danger" })  
  38. </div>  
  39. </div>  
  40. <div class="form-group row">  
  41. @Html.LabelFor(model => model.Account.Description, new { @class = "col-sm-5 control-label" })  
  42. <div class="col-sm-5">  
  43. @Html.EditorFor(model => model.Account.Description)  
  44. </div>  
  45. </div>  
  46. <div class="form-group row">  
  47. @Html.LabelFor(model => model.Account.StartDate, new { @class = "col-sm-5 control-label" })  
  48. <div class="col-sm-4">  
  49. @(Html.DevExtreme().DateBoxFor(m => m.Account.StartDate)  
  50. .ID("AccountStartDate")  
  51. .DisplayFormat(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  52. .Placeholder(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  53. .ShowClearButton(false)  
  54. .InvalidDateMessage("The date must have the following format: " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  55. )  
  56. @Html.ValidationMessageFor(model => model.Account.StartDate, ""new { @class = "text-danger" })  
  57. </div>  
  58. </div>  
  59. </div>  
  60. </div>  
  61. <h5 class="info-text" style="text-align:center">  
  62. Does this account have portfolios?  
  63. @*<input id="toggle-portfolios" type="checkbox" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" style="margin-left:10px;">*@  
  64. <input type="button" class="btn btn-success" id="btnYes" onclick="toggleOn()" value="Yes">  
  65. <input type="button" class="btn btn-danger" id="btnNo" onclick="toggleOff()" value="No">  
  66. </h5>  
  67. <div class="portfoliosForm">  
  68. <div class="form-horizontal">  
  69. <div class="row1">  
  70. <div class="box box-solid">  
  71. <div class="box-header">  
  72. </div>  
  73. <div class="box-body">  
  74. <div class="form-group row">  
  75. <h5 class="col-sm-5" style="text-align:right">Choose an existing product</h5>  
  76. <div class="col-sm-5">  
  77. @(Html.LabelFor(m => m.ProductId))<br>  
  78. @(Html.DropDownListFor(m => m.ProductId, new SelectList(Model.DDLProducts.OrderBy(x => x.Text), "Value""Text"), "Please Select..."new { @class = "form-control", @id = "ddlProduct" }))  
  79. </div>  
  80. </div>  
  81. <div class="form-group row">  
  82. @*@Html.LabelFor(model => model.InvetsmentDate, new { @class = "col-sm-5 control-label" })*@  
  83. <h5 class="col-sm-5" style="text-align:right">Start date</h5>  
  84. <div class="col-sm-5">  
  85. @(Html.DevExtreme().DateBoxFor(m => m.InvetsmentDate)  
  86. .ID("InvestmentStartDate")  
  87. .DisplayFormat(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  88. .Placeholder(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  89. .ShowClearButton(false)  
  90. .InvalidDateMessage("The date must have the following format: " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  91. )  
  92. @Html.ValidationMessageFor(model => model.InvetsmentDate, ""new { @class = "text-danger" })  
  93. </div>  
  94. </div>  
  95. </div>  
  96. </div>  
  97. </div>  
  98. </div>  
  99. </div>  
  100. </div>  
  101. <div class="modal-footer">  
  102. <button type="submit" class="btn btn-primary" id="submitAccountEdit">Save</button>  
  103. <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>  
  104. </div>  
  105. }  
  106. @Scripts.Render("~/bundles/jqueryval")  
  107. @Scripts.Render("~/bundles/wizard")  
  108. <script>  
  109. $(document).ready(function () {  
  110. $('.portfoliosForm').hide();  
  111. });  
  112. </script>  
  113. <script>  
  114. function toggleOn() {  
  115. $('.portfoliosForm').css("display""block");  
  116. }  
  117. function toggleOff() {  
  118. $('.portfoliosForm').css("display""none");  
  119. }  
  120. </script>
Controller
  1. [HttpGet]  
  2. public ActionResult AddAccountModal(int clientId)  
  3. {  
  4. if (_logger.IsInfoEnabled)  
  5. _logger.LogInfo(string.Format("Entering AddAccountModal with ID {0}", clientId));  
  6. using (var dbContextScope = _dbContextScopeFactory.CreateReadOnly())  
  7. {  
  8. // Only coded for adding new accounts right now  
  9. AccountSetup.Models.AccountDetailViewModel model = new AccountSetup.Models.AccountDetailViewModel()  
  10. {  
  11. Account = new AccountSetup.Models.OrganizationViewModel()  
  12. {  
  13. StartDate = DateTime.Now.Date  
  14. },  
  15. Client = new AccountSetup.Models.OrganizationHierarchyViewModel()  
  16. {  
  17. ParentId = clientId  
  18. },  
  19. DDLProducts = SelectListItemHelper.Organizations(GetCustomerId(), "PR"),  
  20. InvetsmentDate = DateTime.Now.Date  
  21. };  
  22. if (_logger.IsInfoEnabled)  
  23. _logger.LogInfo("Exiting AddAccountModal");  
  24. return PartialView(model);  
  25. }  
  26. }
  1. [HttpPost]  
  2. [ValidateAntiForgeryToken]  
  3. public ActionResult AddAccountModal(AccountSetup.Models.AccountDetailViewModel model)  
  4. {  
  5. using (var dbContextScope = _dbContextScopeFactory.Create())  
  6. {  
  7. User user = _Login.GetCurrentUser();  
  8. AccountValidationController accountValidation = new AccountValidationController();  
  9. // Edit not yet implemented!  
  10. var isEdit = model.Account.Id > 0;  
  11. if (isEdit)  
  12. {  
  13. var acct = _AcRepo.GetAccount(model.Account.Id, user);  
  14. acct.Name = model.Account.Name;  
  15. acct.OrganizationNumber = model.Account.Number;  
  16. acct.Description = model.Account.Description;  
  17. var errorMsg = accountValidation.CheckOrgForDuplicatesNameAndNumber(acct, "AC", _Login.GetCurrentUserCustomer().Id);  
  18. if (errorMsg.Count > 0)  
  19. {  
  20. errorMsg.ForEach(m =>  
  21. {  
  22. ModelState.AddModelError("", m);  
  23. });  
  24. return PartialView("AddAccountModal", model);  
  25. }  
  26. if (acct.StartDate != model.Account.StartDate)  
  27. {  
  28. // if changing then start date must be before first fee  
  29. DateTime firstFeeDate = model.Account.StartDate;  
  30. var feeRepo = new FeeRepository(_ambientDbContextLocator);  
  31. var fees = feeRepo.GetActiveFeesForAccount(acct.Id);  
  32. if (fees.Any())  
  33. {  
  34. firstFeeDate = fees.First().PeriodStartDate.Value;  
  35. }  
  36. if (model.Account.StartDate > firstFeeDate)  
  37. {  
  38. ModelState.AddModelError("""Account has already been billed. Start Date must be on or before " + firstFeeDate.ToShortDateString());  
  39. return PartialView("EditAccountModal", model);  
  40. }  
  41. var userId = _Login.GetCurrentUser().UserId;  
  42. var now = DateTime.Now;  
  43. // if moving earlier, then update start date of account-level attributes  
  44. if (model.Account.StartDate < acct.StartDate)  
  45. UpdateAttributesStartDate(acct.UserCodeValues, model.Account.StartDate, userId, now, "EditAccountModal");  
  46. else  
  47. // if moving later, then update start date of investment, account-level attributes, investment-level attributes, and participants  
  48. {  
  49. UpdateAttributesStartDate(acct.UserCodeValues, model.Account.StartDate, userId, now, "EditAccountModal");  
  50. PropagateStartDate(acct, model.Account.StartDate, userId, now, "EditAccountModal");  
  51. }  
  52. _AcRepo.AddAuditNote("Updating start date for account " + acct.GetDisplay() + ".", acct, user);  
  53. acct.StartDate = model.Account.StartDate;  
  54. acct.StatusCode = OrgStatus.P.SmartCode; // set to Pending  
  55. }  
  56. if (model.Client.ParentId != 0)  
  57. {  
  58. OrganizationHierarchy client = _AcRepo.GetClientByAccount(acct.Id);  
  59. if (client == null)  
  60. {  
  61. client = new OrganizationHierarchy  
  62. {  
  63. ParentOrganizationId = model.Client.ParentId,  
  64. ChildOrganizationId = acct.Id,  
  65. StartDate = acct.StartDate,  
  66. StatusCode = "A"  
  67. };  
  68. _AcRepo.AddOrganizationHierarchy(client, user);  
  69. }  
  70. else  
  71. {  
  72. if (client.ParentOrganizationId != model.Client.ParentId)  
  73. {  
  74. client.ParentOrganizationId = model.Client.ParentId;  
  75. }  
  76. }  
  77. }  
  78. //acct.Name = model.Account.Name;  
  79. //acct.OrganizationNumber = model.Account.Number;  
  80. //acct.Description = model.Account.Description;  
  81. //_AcRepo.SaveAccount(acct, _Login.GetCurrentUser());  
  82. _AcRepo.UpdateWithUser(acct, user.UserId, "AddAccountModal");  
  83. }  
  84. else  
  85. {  
  86. if (!ModelState.IsValid)  
  87. {  
  88. return PartialView("AddAccountModal", model);  
  89. }  
  90. var acct = new Organization()  
  91. {  
  92. Name = model.Account.Name,  
  93. OrganizationNumber = model.Account.Number,  
  94. Description = model.Account.Description,  
  95. StartDate = model.Account.StartDate,  
  96. StatusCode = "P",  
  97. CustomerId = GetCustomerId(),  
  98. TypeCode = "AC",  
  99. OrganizationTypeId = _AcRepo.FindByDetached<OrganizationType>(o => o.OrganizationTypeCode == "AC").FirstOrDefault().Id  
  100. };  
  101. var errorMsg = accountValidation.CheckOrgForDuplicatesNameAndNumber(acct, "AC", _Login.GetCurrentUserCustomer().Id);  
  102. if (errorMsg.Count > 0)  
  103. {  
  104. errorMsg.ForEach(m =>  
  105. {  
  106. ModelState.AddModelError("", m);  
  107. });  
  108. model.DDLProducts = SelectListItemHelper.Organizations(acct.CustomerId, "PR");  
  109. return PartialView("AddAccountModal", model);  
  110. }  
  111. var clientOH = new OrganizationHierarchy  
  112. {  
  113. ParentOrganizationId = model.Client.ParentId,  
  114. Child = acct,  
  115. StartDate = acct.StartDate,  
  116. StatusCode = "A"  
  117. };  
  118. var client = _AcRepo.FindByDetached<Organization>(o => o.Id == model.Client.ParentId).First();  
  119. _AcRepo.AddOrganizationHierarchy(clientOH, user);  
  120. _AcRepo.AddWithUser(acct, user.UserId, "AddAccountModal");  
  121. if (model.ProductId != null)  
  122. {  
  123. Organization portfolio = _AcRepo.GetProductByProductId((int)model.ProductId, GetCustomerId());  
  124. var product = new Organization()  
  125. {  
  126. Name = portfolio.Name,  
  127. OrganizationNumber = portfolio.OrganizationNumber,  
  128. Description = portfolio.Description,  
  129. StartDate = model.InvetsmentDate,  
  130. StatusCode = "P",  
  131. CustomerId = GetCustomerId(),  
  132. TypeCode = portfolio.TypeCode,  
  133. OrganizationTypeId = _AcRepo.FindByDetached<OrganizationType>(o => o.OrganizationTypeCode == "PR").FirstOrDefault().Id  
  134. };  
  135. Organization organizationExist = _AcRepo.GetOrganizationByUniqueIndex(portfolio.Name, "PR", product.CustomerId, portfolio.OrganizationNumber);  
  136. OrganizationHierarchy oh = null;  
  137. if (organizationExist == null)  
  138. {  
  139. oh = new OrganizationHierarchy  
  140. {  
  141. Parent = acct,  
  142. Child = product,  
  143. StartDate = product.StartDate,  
  144. StatusCode = "A"  
  145. };  
  146. }  
  147. else  
  148. {  
  149. oh = new OrganizationHierarchy  
  150. {  
  151. Parent = acct,  
  152. Child = organizationExist,  
  153. StartDate = product.StartDate,  
  154. StatusCode = "A"  
  155. };  
  156. }  
  157. _AcRepo.AddOrganizationHierarchy(oh, user);  
  158. if (organizationExist == null)  
  159. {  
  160. _AcRepo.AddWithUser(product, user.UserId, "AddAccountModal");  
  161. }  
  162. }  
  163. else  
  164. {  
  165. //Create a default product  
  166. var defaultProduct = new Organization()  
  167. {  
  168. Name = acct.Name,  
  169. OrganizationNumber = acct.OrganizationNumber,  
  170. Description = acct.Description,  
  171. StartDate = acct.StartDate,  
  172. StatusCode = "P",  
  173. CustomerId = GetCustomerId(),  
  174. TypeCode = "PR",  
  175. OrganizationTypeId = _AcRepo.FindByDetached<OrganizationType>(o => o.OrganizationTypeCode == "PR").FirstOrDefault().Id  
  176. };  
  177. Organization organizationExist = _AcRepo.GetOrganizationByUniqueIndex(defaultProduct.Name, "PR", defaultProduct.CustomerId, defaultProduct.OrganizationNumber);  
  178. OrganizationHierarchy oh = null;  
  179. if (organizationExist == null)  
  180. {  
  181. oh = new OrganizationHierarchy  
  182. {  
  183. Parent = acct,  
  184. Child = defaultProduct,  
  185. StartDate = defaultProduct.StartDate,  
  186. StatusCode = "A"  
  187. };  
  188. }  
  189. else  
  190. {  
  191. oh = new OrganizationHierarchy  
  192. {  
  193. Parent = acct,  
  194. Child = organizationExist,  
  195. StartDate = defaultProduct.StartDate,  
  196. StatusCode = "A"  
  197. };  
  198. }  
  199. _AcRepo.AddOrganizationHierarchy(oh, user);  
  200. if (organizationExist == null)  
  201. {  
  202. _AcRepo.AddWithUser(defaultProduct, user.UserId, "AddAccountModal");  
  203. }  
  204. }  
  205. DoAuditableChange("Adding account " + acct.GetDisplay(), client, user);  
  206. }  
  207. dbContextScope.SaveChanges();  
  208. }  
  209. return Json(new { success = true });  
  210. }  

Answers (11)