public async Task <IActionResult> Create(
            [Bind("EndDate", "InitialDate", "ShareClassName", "CSSFCode", "Status", "FACode",
                  "TACode", "LEICode", "InvestorType", "ShareType ", "CurrencyCode",
                  "CountryIssue", "CountryRisk", "EmissionDate", "InceptionDate", "LastNavDate",
                  "ExpiryDate", "InitialPrice", "AccountingCode", "IsHedged", "IsListed",
                  "BloombergMarket", "BloombergCode", "BloombergId", "ISINCode", "ValorCode",
                  "WKN", "DateBusinessYear", "ProspectusCode", "SubFundContainer",
                  "RecaptchaValue")] CreateShareClassInputModel model)
        {
            bool doesExist = await this.service.DoesExist(model.ShareClassName);

            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 = DateTimeExtensions.ToWebFormat(model.InitialDate.AddDays(1));

            return(this.ShowInfo(
                       this.sharedLocalizer.GetHtmlString(InfoMessages.SuccessfulCreate),
                       EndpointsConstants.RouteDetails + EndpointsConstants.ShareClassArea,
                       new { area = EndpointsConstants.ShareClassArea, id = subFundId, date = date }));
        }
        public async Task <int> Create(CreateShareClassInputModel model)
        {
            ShareClassPostDto        dto           = AutoMapperConfig.MapperInstance.Map <ShareClassPostDto>(model);
            ShareClassForeignKeysDto dtoForeignKey = AutoMapperConfig.MapperInstance.Map <ShareClassForeignKeysDto>(model);

            dto.EndDate     = DateTimeExtensions.ToSqlFormat(model.EndDate);
            dto.ContainerId = await this.repositoryContainer.All()
                              .Where(f => f.SfOfficialSubFundName == model.SubFundContainer)
                              .Select(fc => fc.SfId)
                              .FirstOrDefaultAsync();

            await this.SetForeignKeys(dto, dtoForeignKey);

            var parameters = Deserializer.ImportParameters(EndpointsConstants.ShareClassArea + EndpointsConstants.ActionCreate);

            var procedure = StringExtensions.BuildProcedure(
                SqlProcedureDictionary.CreateShareClass, parameters);

            SqlCommand command = this.AssignBaseParameters(dto, procedure, parameters);

            // Assign particular parameters
            command.Parameters.AddRange(new[]
            {
                new SqlParameter(parameters[26].Name, SqlDbType.Int)
                {
                    Value = dto.ContainerId
                },
                new SqlParameter(parameters[27].Name, SqlDbType.NVarChar)
                {
                    Value = dto.EndDate
                },
            });

            await this.sqlManager.ExecuteProcedure(command);

            var subFundId = this.repository.All()
                            .Where(sf => sf.ScOfficialShareClassName == dto.ShareClassName)
                            .Select(sf => sf.ScId)
                            .FirstOrDefault();

            return(subFundId);
        }