public RegionViewModel GetAllRegions()
        {
            var mod = new RegionViewModel();
            mod.IsValid = true;
            try
            {
                mod.Regions = _bdmSvc.GetAllRegions(AppConstants.SITE_CODE);//.Map(mod.Regions);
            }
            catch (Exception ex)
            {
                mod.IsValid = false;
                mod.Message = ex.Message;
            }

            return mod;
        }
        public RegionViewModel ModifyRegion(RegionDE mod)
        {
            RegionViewModel model = new RegionViewModel();

            try
            {
                DBOperations op = mod.IsActive ? DBOperations.Update : DBOperations.Delete;
                mod.SiteCode = AppConstants.SITE_CODE;
                _bdmSvc.ModifyRegion(mod);

                model.Region = new RegionDE();
                model.FieldId = "regionCode";
                model.Regions = _bdmSvc.GetAllRegions(AppConstants.SITE_CODE); //.GetAllRegions().Map(model.Regions);
                model.Message = op == DBOperations.Update ? string.Format(AppConstants.CRUD_UPDATE, "Region") : string.Format(AppConstants.CRUD_DELETE, "Region");
            }
            catch (Exception ex)
            {
                model.IsValid = false;
                  model.Message = ex.Message;
                  if (ex.Message.Contains("Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions."))
                      model.Message = "Unable to modify Region Code";
            }
            return model;
        }
        public RegionViewModel AddRegion(RegionViewModel model)
        {
            try
            {
                model.IsValid = model.Validate();
                if (model.IsValid)
                {
                    if (_bdmSvc.RegionCodeExists(AppConstants.SITE_CODE, model.Region.RegionCode))
                    {
                        model.FieldId = "regionCode";
                        model.Message = string.Format(AppConstants.VALIDATION_ALREADY_EXISTS, "Region Code");
                        model.IsValid = false;
                    }

                    if (model.IsValid)
                    {
                        model.Region.SiteCode = AppConstants.SITE_CODE;
                        _bdmSvc.AddRegion(model.Region);

                        model.FieldId = "regionCode";
                        model.Region = new RegionDE();
                        model.Regions = _bdmSvc.GetAllRegions(AppConstants.SITE_CODE);
                        model.Message = string.Format(AppConstants.CRUD_CREATE, "Region");
                    }
                }
            }
            catch (Exception ex)
            {
                model.IsValid = false;
                model.Message = ex.Message;
            }

            return model;
        }