public async Task <IActionResult> Create( [Bind("InitialDate", "EndDate", "SubFundName", "CSSFCode", "Status", "FACode", "TACode", "LEICode", "DBCode", "FundContainer", "FirstNavDate", "LastNavDate", "CSSFAuthDate", "ExpiryDate", "CesrClass", "GeographicalFocus", "GlobalExposure", "CurrencyCode", "NavFrequency", "ValuationDate", "CalculationDate", "AreDerivatives", "DerivMarket", "DerivPurpose", "PrincipalAssetClass", "TypeOfMarket", "PrincipalInvestmentStrategy", "ClearingCode", "SfCatMorningStar", "SfCatSix", "SfCatBloomberg", "RecaptchaValue")] CreateSubFundInputModel model) { bool doesExist = await this.service.DoesExist(model.SubFundName); if (!this.ModelState.IsValid || doesExist) { if (doesExist) { this.ShowError(this.sharedLocalizer.GetHtmlString(ErrorMessages.ExistingEntityName)); } this.SetViewDataValues(); return(this.View(model)); } var subFundId = await this.service.Create(model); var date = DateTimeParser.ToWebFormat(model.InitialDate.AddDays(1)); return(this.ShowInfo( this.sharedLocalizer.GetHtmlString(InfoMessages.SuccessfulCreate), GlobalConstants.SubFundDetailsRouteName, new { area = GlobalConstants.SubFundAreaName, id = subFundId, date = date })); }
public async Task <int> Create(CreateSubFundInputModel model) { SubFundPostDto dto = AutoMapperConfig.MapperInstance.Map <SubFundPostDto>(model); SubFundForeignKeysDto dtoForeignKey = AutoMapperConfig.MapperInstance.Map <SubFundForeignKeysDto>(model); dto.EndDate = DateTimeExtensions.ToSqlFormat(model.EndDate); dto.ContainerId = await this.repositoryContainer.All() .Where(f => f.FOfficialFundName == model.FundContainer) .Select(fc => fc.FId) .FirstOrDefaultAsync(); await this.SetForeignKeys(dto, dtoForeignKey); var parameters = Deserializer.ImportParameters( EndpointsConstants.DisplaySub + EndpointsConstants.FundArea + EndpointsConstants.ActionCreate); var procedure = StringExtensions.BuildProcedure( SqlProcedureDictionary.CreateSubFund, parameters); SqlCommand command = this.AssignBaseParameters(dto, procedure, parameters); // Assign particular parameters command.Parameters.AddRange(new[] { new SqlParameter(parameters[29].Name, SqlDbType.Int) { Value = dto.ContainerId }, new SqlParameter(parameters[30].Name, SqlDbType.NVarChar) { Value = dto.EndDate }, }); await this.sqlManager.ExecuteProcedure(command); var subFundId = this.repository.All() .Where(sf => sf.SfOfficialSubFundName == dto.SubFundName) .Select(sf => sf.SfId) .FirstOrDefault(); return(subFundId); }
public async Task <int> Create(CreateSubFundInputModel model) { SubFundPostDto dto = AutoMapperConfig.MapperInstance.Map <SubFundPostDto>(model); SubFundForeignKeysDto dtoForeignKey = AutoMapperConfig.MapperInstance.Map <SubFundForeignKeysDto>(model); dto.EndDate = DateTimeParser.ToSqlFormat(model.EndDate); dto.ContainerId = await this.repositoryContainer.All() .Where(f => f.FOfficialFundName == model.FundContainer) .Select(fc => fc.FId) .FirstOrDefaultAsync(); await this.SetForeignKeys(dto, dtoForeignKey); SqlCommand command = this.AssignBaseParameters(dto, SqlProcedureDictionary.CreateSubFund); // Assign particular parameters // Assign particular parameters command.Parameters.AddRange(new[] { new SqlParameter("@fundcontainer", SqlDbType.Int) { Value = dto.ContainerId }, new SqlParameter("@sf_endDate", SqlDbType.NVarChar) { Value = dto.EndDate }, }); await this.sqlManager.ExecuteProcedure(command); var subFundId = this.repository.All() .Where(sf => sf.SfOfficialSubFundName == dto.SubFundName) .Select(sf => sf.SfId) .FirstOrDefault(); return(subFundId); }