public TakeRateDataItem ToDataItem()
        {
            if (IsPowertrainChange)
            {
                return(new EmptyTakeRateDataItem());
            }
            var dataItem = new TakeRateDataItem()
            {
                Volume                                    = Volume.GetValueOrDefault(),
                PercentageTakeRate                        = PercentageTakeRate.GetValueOrDefault(),
                ModelId                                   = !IsFdpModel?GetModelId() : null,
                                               FdpModelId = IsFdpModel ? GetModelId() : null,
                                               FeatureId  = !IsFdpFeature?GetFeatureId() : null,
                                                                FdpFeatureId = IsFdpFeature ? GetFeatureId() : null,
                                                                MarketId     = MarketId
            };

            if (!string.IsNullOrEmpty(Note))
            {
                dataItem.Notes = new List <TakeRateDataItemNote>()
                {
                    new TakeRateDataItemNote(Note)
                };
            }
            return(dataItem);
        }
 public async Task<TakeRateDataItem> SaveDataItem(TakeRateDataItem dataItemToSave)
 {
     return await Task.FromResult(_takeRateDataStore.TakeRateDataItemSave(dataItemToSave));
 }
        public TakeRateDataItem TakeRateDataItemSave(TakeRateDataItem dataItemToSave)
        {
            TakeRateDataItem retVal = new EmptyTakeRateDataItem();

            using (IDbConnection conn = DbHelper.GetDBConnection())
            {
                try
                {
                    var para = new DynamicParameters();
                    int? takeRateDataItemId = null;
             
                    para.Add("@FdpTakeRateDataItemId", dataItemToSave.FdpTakeRateDataItemId, DbType.Int32, ParameterDirection.InputOutput);
                    para.Add("@DocumentId", dataItemToSave.DocumentId, DbType.Int32);
                    para.Add("@ModelId", dataItemToSave.ModelId, DbType.Int32);
                    para.Add("@FdpModelId", dataItemToSave.FdpModelId, DbType.Int32);
                    para.Add("@FeatureId", dataItemToSave.FeatureId, DbType.Int32);
                    para.Add("@FdpFeatureId", dataItemToSave.FdpFeatureId, DbType.Int32);
                    para.Add("@MarketGroupId", dataItemToSave.MarketGroupId, DbType.Int32);
                    para.Add("@MarketId", dataItemToSave.MarketId, DbType.Int32);
                    para.Add("@Volume", dataItemToSave.Volume, DbType.Int32);
                    para.Add("@PercentageTakeRate", dataItemToSave.PercentageTakeRate, DbType.Decimal);
                    para.Add("@FeaturePackId", dataItemToSave.FeaturePackId, DbType.Int32);
                    para.Add("@CDSID", CurrentCDSID, DbType.String);

                    var rows = conn.Execute(fdpTakeRateDataItemSaveStoredProcedureName, para, commandType: CommandType.StoredProcedure);
                    if (rows > 0)
                    {
                        takeRateDataItemId = para.Get<int?>("@FdpTakeRateDataItemId");
                    }
                    
                    //// Save any notes 
                    //foreach (var note in dataItemToSave.Notes.Where(n => !n.FdpTakeRateDataItemNoteId.HasValue))
                    //{
                    //    note.FdpTakeRateDataItemId = takeRateDataItemId;
                    //    TakeRateDataItemNoteSave(note);
                    //}

                    retVal = TakeRateDataItemGet(new TakeRateFilter { TakeRateDataItemId = takeRateDataItemId });
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    throw;
                }
            }

            return retVal;
        }
 public TakeRateDataItem ToDataItem()
 {
     if (IsPowertrainChange)
     {
         return new EmptyTakeRateDataItem();
     }
     var dataItem = new TakeRateDataItem()
     {
         Volume = Volume.GetValueOrDefault(),
         PercentageTakeRate = PercentageTakeRate.GetValueOrDefault(),
         ModelId = !IsFdpModel ? GetModelId() : null,
         FdpModelId = IsFdpModel ? GetModelId() : null,
         FeatureId = !IsFdpFeature ? GetFeatureId() : null,
         FdpFeatureId = IsFdpFeature ? GetFeatureId() : null,
         MarketId = MarketId
     };
     if (!string.IsNullOrEmpty(Note)) {
         dataItem.Notes = new List<TakeRateDataItemNote>() { new TakeRateDataItemNote(Note) };
     }
     return dataItem;
 }