Skip to content
Loading
Value cannot be null" Parameter Name:source  
  • class="form-group row">  
  • @Html.LabelFor(model => model.Account.Number, new { @class = "col-sm-5 control-label", @required = "required" })  
  • class="col-sm-5">  
  • @Html.EditorFor(model => model.Account.Number)  
  • @Html.ValidationMessageFor(model => model.Account.Number, ""new { @class = "text-danger" })  
  •   
  •   
  • class="form-group row">  
  • @Html.LabelFor(model => model.Account.Description, new { @class = "col-sm-5 control-label" })  
  • class="col-sm-5">  
  • @Html.EditorFor(model => model.Account.Description)  
  •   
  •   
  • class="form-group row">  
  • @Html.LabelFor(model => model.Account.StartDate, new { @class = "col-sm-5 control-label" })  
  • class="col-sm-4">  
  • @(Html.DevExtreme().DateBoxFor(m => m.Account.StartDate)  
  • .ID("AccountStartDate")  
  • .DisplayFormat(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  • .Placeholder(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  • .ShowClearButton(false)  
  • .InvalidDateMessage("The date must have the following format: " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  • )  
  • @Html.ValidationMessageFor(model => model.Account.StartDate, ""new { @class = "text-danger" })  
  •   
  •   
  •   
  •   
  • class="info-text" style="text-align:center">  
  • Does this account have portfolios?  
  • @*"toggle-portfolios" type="checkbox" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" style="margin-left:10px;">*@  
  • "button" class="btn btn-success" id="btnYes" onclick="toggleOn()" value="Yes">  
  • "button" class="btn btn-danger" id="btnNo" onclick="toggleOff()" value="No">  
  •   
  • class="portfoliosForm">  
  • class="form-horizontal">  
  • class="row1">  
  • class="box box-solid">  
  • class="box-header">  
  •   
  • class="box-body">  
  • class="form-group row">  
  • class="col-sm-5" style="text-align:right">Choose an existing product  
  • class="col-sm-5">  
  • @(Html.LabelFor(m => m.ProductId))
      
  • @(Html.DropDownListFor(m => m.ProductId, new SelectList(Model.DDLProducts.OrderBy(x => x.Text), "Value""Text"), "Please Select..."new { @class = "form-control", @id = "ddlProduct" }))  
  •   
  •   
  • class="form-group row">  
  • @*@Html.LabelFor(model => model.InvetsmentDate, new { @class = "col-sm-5 control-label" })*@  
  • class="col-sm-5" style="text-align:right">Start date  
  • class="col-sm-5">  
  • @(Html.DevExtreme().DateBoxFor(m => m.InvetsmentDate)  
  • .ID("InvestmentStartDate")  
  • .DisplayFormat(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  • .Placeholder(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  • .ShowClearButton(false)  
  • .InvalidDateMessage("The date must have the following format: " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)  
  • )  
  • @Html.ValidationMessageFor(model => model.InvetsmentDate, ""new { @class = "text-danger" })  
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  • class="modal-footer">  
  • "submit" class="btn btn-primary" id="submitAccountEdit">Save  
  • "button" class="btn btn-primary" data-dismiss="modal">Cancel  
  •   
  • }  
  • @Scripts.Render("~/bundles/jqueryval")  
  • @Scripts.Render("~/bundles/wizard")  
  •   
  • 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(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(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(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(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. }  

    11 Replies

    Know the answer? Post it — somebody with the same question will find it here.