Exemple #1
0
        public static int Create(CountryDataModel data, RequestProfile requestProfile)
        {
            var sql   = Save(data, "Create", requestProfile);
            var newId = DBDML.RunScalarSQL("Country.Insert", sql, DataStoreKey);

            return(Convert.ToInt32(newId));
        }
Exemple #2
0
        private static string CreateOrUpdate(CountryDataModel data, RequestProfile requestProfile, string action)
        {
            var sql = "EXEC ";

            switch (action)
            {
            case "Create":
                sql += "dbo.CountryInsert  " +
                       " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId) +
                       ", " + ToSQLParameter(BaseDataModel.BaseDataColumns.ApplicationId, requestProfile.ApplicationId);
                break;

            case "Update":
                sql += "dbo.CountryUpdate  " +
                       " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId);
                break;

            default:
                break;
            }

            sql = sql + ", " + ToSQLParameter(data, CountryDataModel.DataColumns.CountryId) +
                  ", " + ToSQLParameter(data, CountryDataModel.DataColumns.Name) +
                  ", " + ToSQLParameter(data, CountryDataModel.DataColumns.TimeZoneId) +
                  ", " + ToSQLParameter(data, CountryDataModel.DataColumns.Description) +
                  ", " + ToSQLParameter(data, CountryDataModel.DataColumns.SortOrder);
            return(sql);
        }
Exemple #3
0
        public override int?Save(string action)
        {
            var data = new CountryDataModel();

            data.CountryId   = CountryId;
            data.TimeZoneId  = TimeZoneId;
            data.Name        = Name;
            data.Description = Description;
            data.SortOrder   = SortOrder;

            if (action == "Insert")
            {
                var dtCountry = Framework.Components.Core.CountryDataManager.DoesExist(data, SessionVariables.RequestProfile);

                if (dtCountry.Rows.Count == 0)
                {
                    Framework.Components.Core.CountryDataManager.Create(data, SessionVariables.RequestProfile);
                }
                else
                {
                    throw new Exception("Record with given ID already exists.");
                }
            }
            else
            {
                Framework.Components.Core.CountryDataManager.Update(data, SessionVariables.RequestProfile);
            }

            // not correct ... when doing insert, we didn't get/change the value of CountryID ?
            return(CountryId);
        }
Exemple #4
0
        public void Delete(string value)
        {
            var dataQuery = new CountryDataModel();

            dataQuery.CountryId = int.Parse(value);
            CountryDataManager.Delete(dataQuery, SessionVariables.RequestProfile);
        }
Exemple #5
0
        public static string ToSQLParameter(CountryDataModel data, string dataColumnName)
        {
            var returnValue = "NULL";

            switch (dataColumnName)
            {
            case CountryDataModel.DataColumns.CountryId:
                if (data.CountryId != null)
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CountryDataModel.DataColumns.CountryId, data.CountryId);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CountryDataModel.DataColumns.CountryId);
                }
                break;

            case CountryDataModel.DataColumns.TimeZoneId:
                if (data.TimeZoneId != null)
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CountryDataModel.DataColumns.TimeZoneId, data.TimeZoneId);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CountryDataModel.DataColumns.TimeZoneId);
                }
                break;

            default:
                returnValue = StandardDataManager.ToSQLParameter(data, dataColumnName);
                break;
            }

            return(returnValue);
        }
Exemple #6
0
        protected override void ShowData(int countryId)
        {
            base.ShowData(countryId);

            oDetailButtonPanel.SetId = SetId;

            Clear();

            var data = new CountryDataModel();

            data.CountryId = countryId;

            var items = Framework.Components.Core.CountryDataManager.GetEntityDetails(data, SessionVariables.RequestProfile);

            // should only have single match
            if (items.Count == 1)
            {
                var item = items[0];

                lblCountryId.Text   = item.CountryId.ToString();
                lblTimeZone.Text    = item.TimeZoneId.ToString();
                lblName.Text        = item.Name;
                lblDescription.Text = item.Description;
                lblSortOrder.Text   = item.SortOrder.ToString();

                oUpdateInfo.LoadText(item.UpdatedDate, item.UpdatedBy, item.LastAction);

                oHistoryList.Setup(PrimaryEntity, countryId, "Country");
            }
        }
Exemple #7
0
        public static DataTable DoesExist(CountryDataModel data, RequestProfile requestProfile)
        {
            var doesExistRequest = new CountryDataModel();

            doesExistRequest.Name = data.Name;

            return(Search(doesExistRequest, requestProfile));
        }
Exemple #8
0
        public static DataTable GetDetails(CountryDataModel data, RequestProfile requestProfile)
        {
            var list = GetEntityDetails(data, requestProfile);

            var table = list.ToDataTable();

            return(table);
        }
Exemple #9
0
        public static string ToSQLParameter(CountryDataModel data, string dataColumnName)
        {
            var returnValue = "NULL";

            switch (dataColumnName)
            {
            case CountryDataModel.DataColumns.CountryId:
                if (data.CountryId != null)
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CountryDataModel.DataColumns.CountryId, data.CountryId);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CountryDataModel.DataColumns.CountryId);
                }
                break;

            case CountryDataModel.DataColumns.Name:
                if (!string.IsNullOrEmpty(data.Name))
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, CountryDataModel.DataColumns.Name, data.Name);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CountryDataModel.DataColumns.Name);
                }
                break;

            case CountryDataModel.DataColumns.Description:
                if (!string.IsNullOrEmpty(data.Description))
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, CountryDataModel.DataColumns.Description, data.Description);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CountryDataModel.DataColumns.Description);
                }
                break;

            case CountryDataModel.DataColumns.SortOrder:
                if (data.SortOrder != null)
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CountryDataModel.DataColumns.SortOrder, data.SortOrder);
                }
                else
                {
                    returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CountryDataModel.DataColumns.SortOrder);
                }
                break;


            default:
                returnValue = BaseDataManager.ToSQLParameter(data, dataColumnName);
                break;
            }

            return(returnValue);
        }
Exemple #10
0
        private System.Data.DataTable GetData()
        {
            // TODO: on all export pages
            var data = new CountryDataModel();

            var dt = Framework.Components.Core.CountryDataManager.Search(data, SessionVariables.RequestProfile);

            return(dt);
        }
Exemple #11
0
        public CountryDataModel GetById(string value)
        {
            var dataQuery = new CountryDataModel();

            dataQuery.CountryId = int.Parse(value);
            var result = CountryDataManager.GetEntityDetails(dataQuery, SessionVariables.RequestProfile, 1);

            return(result[0]);
        }
Exemple #12
0
        private DataTable GetData(string name)
        {
            var data = new CountryDataModel();

            data.Name = name;

            var dt = Framework.Components.Core.CountryDataManager.Search(data, SessionVariables.RequestProfile);

            return(dt);
        }
Exemple #13
0
        public static bool DoesExist(CountryDataModel data, RequestProfile requestProfile)
        {
            var doesExistRequest = new CountryDataModel();

            doesExistRequest.Name = data.Name;

            var list = GetEntityDetails(doesExistRequest, requestProfile, 0);

            return(list.Count > 0);
        }
Exemple #14
0
        public IHttpActionResult Post(CountryDataModel country)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var createdCountryId = this.countries.Add(country.Name);

            return(this.Ok(createdCountryId));
        }
Exemple #15
0
        protected override void Clear()
        {
            base.Clear();

            var data = new CountryDataModel();

            CountryId   = data.CountryId;
            TimeZoneId  = data.TimeZoneId;
            Description = data.Description;
            Name        = data.Name;
            SortOrder   = data.SortOrder;
        }
Exemple #16
0
        public static void Delete(CountryDataModel data, RequestProfile requestProfile)
        {
            const string sql = @"dbo.CountryDelete ";

            var parameters =
                new
            {
                AuditId     = requestProfile.AuditId
                , CountryId = data.CountryId
            };

            using (var dataAccess = new DataAccessBase(DataStoreKey))
            {
                dataAccess.Connection.Execute(sql, parameters, commandType: CommandType.StoredProcedure);
            }
        }
Exemple #17
0
        public IHttpActionResult Post([FromBody] CountryDataModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var country = new Country
            {
                Name = model.Name
            };

            this.data.Countries.Add(country);
            this.data.Savechanges();

            return(this.Created(this.Url.ToString(), country));
        }
        public static object PopulateFullCountryData(Country country, bool isFavorite)
        {
            string countryMapURI  = "https://maps.google.com/maps?q=" + country.Name + "&t=&z=3&ie=UTF8&iwloc=&output=embed";
            string countryDataAPI = "https://restcountries.eu/rest/v2/alpha/" + country.ShortName + "?fields=capital;currencies";
            string countryFlag    = "http://www.countryflags.io/" + country.ShortName + "/flat/64.png";

            var    countryDataResponse = Utilities.Get(countryDataAPI);
            var    JsonResponse        = JObject.Parse(countryDataResponse.Result);
            string countryCapital      = JsonResponse["capital"].ToString();

            var    JSONCurrencyResponse = JObject.Parse(JsonResponse["currencies"][0].ToString());
            string currencyCode         = JSONCurrencyResponse["code"].ToString();
            string currencyName         = JSONCurrencyResponse["name"].ToString();

            string currencyDataAPI = "https://free.currencyconverterapi.com/api/v5/convert?q=" + currencyCode + "_INR&compact=ultra";

            string currencyValue = string.Empty;

            try
            {
                var currencyValueResponse     = Utilities.Get(currencyDataAPI);
                var currencyValueJsonResponse = JObject.Parse(currencyValueResponse.Result);
                currencyValue = currencyValueJsonResponse.First.First.ToString();
            }
            catch (System.Exception exception)
            {
                System.Console.WriteLine(exception);
            }

            CountryDataModel countryData = new CountryDataModel()
            {
                IsFavorite     = isFavorite,
                CountryName    = country.Name,
                CountryCode    = country.ShortName,
                CurrencyCode   = currencyCode,
                currencyName   = currencyName,
                CurrencyValue  = currencyValue,
                CountryCapital = countryCapital,
                CountryMapURI  = countryMapURI,
                CountryFlag    = countryFlag
            };

            return(countryData);
        }
Exemple #19
0
        public static void Sync(int newApplicationId, int oldApplicationId, RequestProfile requestProfile)
        {
            // get all records for old Application Id
            var sql = "EXEC dbo.CountrySearch " +
                      " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId) +
                      ", " + ToSQLParameter(BaseDataModel.BaseDataColumns.ApplicationId, oldApplicationId);

            var oDT = new DBDataTable("Country.Search", sql, DataStoreKey);

            // formaulate a new request Profile which will have new Applicationid
            var newRequestProfile = new RequestProfile();

            newRequestProfile.ApplicationId = newApplicationId;
            newRequestProfile.AuditId       = requestProfile.AuditId;

            var timeZoneData = new TimeZoneDataModel();
            var timeZoneList = TimeZoneDataManger.GetEntityDetails(timeZoneData, newRequestProfile);

            foreach (DataRow dr in oDT.DBTable.Rows)
            {
                var fcModeName = dr[CountryDataModel.DataColumns.TimeZone].ToString();

                //get new fc mode id based on fc mode name
                var newTimeZoneId = timeZoneList.Find(x => x.Name == fcModeName).TimeZoneId;

                var data = new CountryDataModel();
                data.ApplicationId = newApplicationId;
                data.Name          = dr[CountryDataModel.DataColumns.Name].ToString();

                // check for existing record in new Application Id
                var dt = DoesExist(data, newRequestProfile);
                if (dt == null || dt.Rows.Count == 0)
                {
                    data.TimeZoneId  = newTimeZoneId;
                    data.Description = dr[CountryDataModel.DataColumns.Description].ToString();
                    data.SortOrder   = Convert.ToInt32(dr[CountryDataModel.DataColumns.SortOrder]);

                    //create in new application id
                    Create(data, newRequestProfile);
                }
            }
        }
Exemple #20
0
        public IHttpActionResult Put(int id, [FromBody] CountryDataModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var country = this.data.Countries.Find(id);

            if (country == null)
            {
                return(this.BadRequest("No such country can be found."));
            }

            country.Name = model.Name;
            this.data.Countries.Update(country);
            this.data.Savechanges();

            return(this.Ok(country));
        }
Exemple #21
0
        public void LoadData(int countryId, bool showId)
        {
            // clear UI

            Clear();

            var dataQuery = new CountryDataModel();

            dataQuery.CountryId = countryId;

            var items = Framework.Components.Core.CountryDataManager.GetEntityDetails(dataQuery, SessionVariables.RequestProfile);

            if (items.Count != 1)
            {
                return;
            }

            var item = items[0];

            CountryId   = item.CountryId;
            TimeZoneId  = item.TimeZoneId;
            Name        = item.Name;
            Description = item.Description;
            SortOrder   = item.SortOrder;

            if (!showId)
            {
                txtCountryId.Text = item.CountryId.ToString();

                // only show Audit History in case of Update page, not for Clone.
                oHistoryList.Setup((int)Framework.Components.DataAccess.SystemEntity.Country, countryId, "Country");
            }
            else
            {
                txtCountryId.Text = String.Empty;
            }

            oUpdateInfo.LoadText(item.UpdatedDate, item.UpdatedBy, item.LastAction);
        }
Exemple #22
0
        public static List <CountryDataModel> GetEntityDetails(CountryDataModel dataQuery, RequestProfile requestProfile, int returnAuditInfo = BaseDataManager.ReturnAuditInfoOnDetails)
        {
            const string sql = @"dbo.CountrySearch ";

            var parameters =
                new
            {
                AuditId           = requestProfile.AuditId
                , ApplicationId   = requestProfile.ApplicationId
                , ReturnAuditInfo = returnAuditInfo
                , CountryId       = dataQuery.CountryId
                , Name            = dataQuery.Name
            };

            List <CountryDataModel> result;

            using (var dataAccess = new DataAccessBase(DataStoreKey))
            {
                result = dataAccess.Connection.Query <CountryDataModel>(sql, parameters, commandType: CommandType.StoredProcedure).ToList();
            }

            return(result);
        }
Exemple #23
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                var      notDeletableIds = new List <int>();
                string[] deleteIndexList = DeleteIds.Split(',');

                if (notDeletableIds.Count == 0)
                {
                    foreach (string index in deleteIndexList)
                    {
                        var data = new CountryDataModel();
                        data.CountryId = int.Parse(index);
                        Framework.Components.Core.CountryDataManager.Delete(data, SessionVariables.RequestProfile);
                    }
                    DeleteAndRedirect();
                }
                else
                {
                    var msg = String.Empty;
                    foreach (var id in notDeletableIds)
                    {
                        if (!string.IsNullOrEmpty(msg))
                        {
                            msg += ", <br/>";
                        }
                        msg += "CountryId: " + id + " has detail records";
                    }
                    Response.Write(msg);
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
Exemple #24
0
        public static void Update(CountryDataModel data, RequestProfile requestProfile)
        {
            var sql = CreateOrUpdate(data, requestProfile, "Update");

            DBDML.RunSQL("Country.Update", sql, DataStoreKey);
        }
Exemple #25
0
 public void Update([FromBody] CountryDataModel data)
 {
     CountryDataManager.Update(data, SessionVariables.RequestProfile);
 }
Exemple #26
0
        public static DataTable Search(CountryDataModel data, RequestProfile requestProfile)
        {
            var list = GetEntityDetails(data, requestProfile, 0);

            return(list.ToDataTable());
        }
Exemple #27
0
        private void SetUserCountry()
        {
            if (drpCountry.SelectedValue != "-1")
            {
                //UserCountryId = Convert.ToInt32(drpCountry.SelectedValue);

                var data = new UserPreferenceDataModel();
                if (UserCountryPreferenceId != null)
                {
                    data.UserPreferenceId = UserCountryPreferenceId;

                    var dt = UserPreferenceDataManager.Search(data, SessionVariables.RequestProfile);
                    if (dt.Rows.Count > 0)
                    {
                        data.UserPreferenceCategoryId = Convert.ToInt32(dt.Rows[0][UserPreferenceDataModel.DataColumns.UserPreferenceCategoryId]);
                        data.UserPreferenceKeyId      = Convert.ToInt32(dt.Rows[0][UserPreferenceDataModel.DataColumns.UserPreferenceKeyId]);
                        data.DataTypeId        = Convert.ToInt32(dt.Rows[0][UserPreferenceDataModel.DataColumns.DataTypeId]);
                        data.Value             = Convert.ToString(drpCountry.SelectedValue);
                        data.ApplicationUserId = SessionVariables.RequestProfile.AuditId;
                        data.ApplicationId     = SessionVariables.RequestProfile.ApplicationId;

                        UserPreferenceDataManager.Update(data, SessionVariables.RequestProfile);
                    }
                }
                else
                {
                    data.UserPreferenceCategoryId = 1;
                    data.UserPreferenceKeyId      = UserCountryKeyId;
                    data.Value             = Convert.ToString(drpCountry.SelectedValue);
                    data.ApplicationUserId = SessionVariables.RequestProfile.AuditId;
                    data.DataTypeId        = UserCountryDataTypeId;
                    data.ApplicationId     = SessionVariables.RequestProfile.ApplicationId;

                    UserPreferenceDataManager.Create(data, SessionVariables.RequestProfile);
                }

                var dataCountry = new CountryDataModel();
                dataCountry.CountryId = Convert.ToInt32(drpCountry.SelectedValue);
                var dtCountry = Framework.Components.Core.CountryDataManager.Search(dataCountry, SessionVariables.RequestProfile);
                if (dtCountry.Rows.Count > 0)
                {
                    var timeZoneId = Convert.ToInt32(dtCountry.Rows[0][CountryDataModel.DataColumns.TimeZoneId]);

                    var dataKey = new UserPreferenceKeyDataModel();
                    dataKey.Name = "UserTimeZone";
                    var dtKeys = Framework.Components.UserPreference.UserPreferenceKeyDataManager.Search(dataKey, SessionVariables.RequestProfile);
                    if (dtKeys != null && dtKeys.Rows.Count > 0)
                    {
                        var keyId      = Convert.ToInt32(dtKeys.Rows[0][UserPreferenceKeyDataModel.DataColumns.UserPreferenceKeyId]);
                        var dataTypeId = Convert.ToInt32(dtKeys.Rows[0][UserPreferenceKeyDataModel.DataColumns.DataTypeId]);

                        data = new UserPreferenceDataModel();
                        data.UserPreferenceKeyId = keyId;

                        var dt = UserPreferenceDataManager.Search(data, SessionVariables.RequestProfile);
                        if (dt.Rows.Count > 0)
                        {
                            data.Value = Convert.ToString(timeZoneId);
                            data.UserPreferenceCategoryId = Convert.ToInt32(dt.Rows[0][UserPreferenceDataModel.DataColumns.UserPreferenceCategoryId]);
                            data.UserPreferenceId         = Convert.ToInt32(dt.Rows[0][UserPreferenceDataModel.DataColumns.UserPreferenceId]);
                            data.DataTypeId        = Convert.ToInt32(dt.Rows[0][UserPreferenceDataModel.DataColumns.DataTypeId]);
                            data.ApplicationUserId = SessionVariables.RequestProfile.AuditId;
                            data.ApplicationId     = SessionVariables.RequestProfile.ApplicationId;
                            UserPreferenceDataManager.Update(data, SessionVariables.RequestProfile);
                        }
                        else
                        {
                            data.Value                    = Convert.ToString(timeZoneId);
                            data.DataTypeId               = dataTypeId;
                            data.UserPreferenceKeyId      = keyId;
                            data.UserPreferenceCategoryId = 1;
                            data.ApplicationUserId        = SessionVariables.RequestProfile.AuditId;
                            data.ApplicationId            = SessionVariables.RequestProfile.ApplicationId;
                            UserPreferenceDataManager.Create(data, SessionVariables.RequestProfile);
                        }
                    }
                }
            }
        }