Пример #1
0
 /// <summary>
 /// Converts a WatchListModel to WatchListEntity.
 /// </summary>
 /// <param name="watchListModel">WatchListModel to be converted to WatchListEntity.</param>
 /// <returns>WatchListEntity corresponding to WatchListModel.</returns>
 public static WatchListEntity ConvertModelToWatchListEntity(WatchListModel watchListModel)
 {
     return(new WatchListEntity
     {
         AlertRequired = watchListModel.AlertRequired,
         AltNameOne = watchListModel.AltNameOne,
         AltNameThree = watchListModel.AltNameThree,
         AltNameTwo = watchListModel.AltNameTwo,
         BseSymbol = watchListModel.BseSymbol,
         CreatedOn = !string.IsNullOrEmpty(watchListModel.CreatedOn) ?
                     DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListModel.CreatedOn)) : null,
         IsActive = watchListModel.IsActive,
         ModifiedOn = !string.IsNullOrEmpty(watchListModel.ModifiedOn) ?
                      DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListModel.ModifiedOn)) : null,
         Name = watchListModel.Name,
         NseSymbol = watchListModel.NseSymbol,
         TempName = watchListModel.TempName,
         WatchListID = watchListModel.WatchListID
     });
 }
        /// <summary>
        /// Method to create search criteria name value pair list for watch list grid. Name has DB column name and value the search string.
        /// </summary>
        /// <param name="watchListSearchModel">The WatchListSearchModel from view.</param>
        /// <returns>Search criteria name value pair list.</returns>
        private IList <KeyValuePair <string, string> > CreateSearchCriteriaListForWatchListGrid(WatchListSearchModel watchListSearchModel)
        {
            var searchCriteriaListForWatchListGrid = new List <KeyValuePair <string, string> >();

            // Create a criteria name value pair for each model field.
            if (watchListSearchModel.AlertRequired != null)
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("AlertRequired",
                                                                                         (bool)watchListSearchModel.AlertRequired ? "1" : "0"));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.AltNameOne))
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("AltNameOne", watchListSearchModel.AltNameOne));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.AltNameThree))
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("AltNameThree", watchListSearchModel.AltNameThree));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.AltNameTwo))
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("AltNameTwo", watchListSearchModel.AltNameTwo));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.BseSymbol))
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("BseSymbol", watchListSearchModel.BseSymbol));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.CreatedOnStart))
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("CreatedOnStart",
                                                                                         DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListSearchModel.CreatedOnStart)).ToString()));
            }
            else if (!string.IsNullOrEmpty(watchListSearchModel.CreatedOnEnd))
            {
                // If only end date is specified, start date will be begining of the end date i.e. 0 hr of end date.
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("CreatedOnStart",
                                                                                         DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListSearchModel.CreatedOnEnd)).ToString()));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.CreatedOnEnd))
            {
                // End date will be end of end date i.e. 2400 hrs of end date or 0 hrs of next day to end date.
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("CreatedOnEnd",
                                                                                         DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListSearchModel.CreatedOnEnd).Value.AddDays(1)).ToString()));
            }
            else if (!string.IsNullOrEmpty(watchListSearchModel.CreatedOnStart))
            {
                // If only start date is specified, end date will be end of start date i.e. 2400 hrs of start date or 0 hr of next day to start date.
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("CreatedOnEnd",
                                                                                         DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListSearchModel.CreatedOnStart).Value.AddDays(1)).ToString()));
            }

            if (watchListSearchModel.IsActive != null)
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("IsActive",
                                                                                         (bool)watchListSearchModel.IsActive ? "1" : "0"));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.ModifiedOnStart))
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("ModifiedOnStart",
                                                                                         DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListSearchModel.ModifiedOnStart)).ToString()));
            }
            else if (!string.IsNullOrEmpty(watchListSearchModel.ModifiedOnEnd))
            {
                // If only end date is specified, start date will be begining of the end date i.e. 0 hr of end date.
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("ModifiedOnStart",
                                                                                         DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListSearchModel.ModifiedOnEnd)).ToString()));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.ModifiedOnEnd))
            {
                // End date will be end of end date i.e. 2400 hrs of end date or 0 hrs of next day to end date.
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("ModifiedOnEnd",
                                                                                         DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListSearchModel.ModifiedOnEnd).Value.AddDays(1)).ToString()));
            }
            else if (!string.IsNullOrEmpty(watchListSearchModel.ModifiedOnStart))
            {
                // If only start date is specified, end date will be end of start date i.e. 2400 hrs of start date or 0 hr of next day to start date.
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("ModifiedOnEnd",
                                                                                         DataFormatter.GetDateTimeInUtcFormat(DataFormatter.FormatStringToDate(watchListSearchModel.ModifiedOnStart).Value.AddDays(1)).ToString()));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.Name))
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("Name", watchListSearchModel.Name));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.NseSymbol))
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("NseSymbol", watchListSearchModel.NseSymbol));
            }

            if (!string.IsNullOrEmpty(watchListSearchModel.TempName))
            {
                searchCriteriaListForWatchListGrid.Add(new KeyValuePair <string, string>("TempName", watchListSearchModel.TempName));
            }

            return(searchCriteriaListForWatchListGrid);
        }