Inheritance: System.Web.UI.Page
Beispiel #1
0
        public List <CountryRegion> GetAll()
        {
            CountryRegionDAC     _countryRegionComponent = new CountryRegionDAC();
            IDataReader          reader             = _countryRegionComponent.GetAllCountryRegion().CreateDataReader();
            List <CountryRegion> _countryRegionList = new List <CountryRegion>();

            while (reader.Read())
            {
                if (_countryRegionList == null)
                {
                    _countryRegionList = new List <CountryRegion>();
                }
                CountryRegion _countryRegion = new CountryRegion();
                if (reader["CountryRegionCode"] != DBNull.Value)
                {
                    _countryRegion.CountryRegionCode = Convert.ToString(reader["CountryRegionCode"]);
                }
                if (reader["Name"] != DBNull.Value)
                {
                    _countryRegion.Name = Convert.ToString(reader["Name"]);
                }
                if (reader["ModifiedDate"] != DBNull.Value)
                {
                    _countryRegion.ModifiedDate = Convert.ToDateTime(reader["ModifiedDate"]);
                }
                _countryRegion.NewRecord = false;
                _countryRegionList.Add(_countryRegion);
            }
            reader.Close();
            return(_countryRegionList);
        }
        // POST: odata/CountryRegions
        public IHttpActionResult Post(CountryRegion countryRegion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _db.CountryRegions.Add(countryRegion);

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CountryRegionExists(countryRegion.CountryRegionCode))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Created(countryRegion));
        }
Beispiel #3
0
        protected void BtnCreate_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                List <Country> countries = CountryService.Instance.GetAll(StoreId).ToList();

                foreach (DefaultCountry defaultCountry in CountryService.Instance.GetDefaultCountries())
                {
                    if (!countries.Any(c => c.RegionCode == defaultCountry.Code || c.Name == defaultCountry.Name))
                    {
                        Country country = new Country(StoreId, defaultCountry.Name, long.Parse(DrpCurrencies.SelectedValue))
                        {
                            RegionCode = defaultCountry.Code
                        };

                        country.Save();

                        foreach (Region region in defaultCountry.Regions)
                        {
                            CountryRegion countryRegion = new CountryRegion(StoreId, region.Name, country.Id)
                            {
                                RegionCode = region.Code
                            };
                            countryRegion.Save();
                        }
                    }
                }

                CreateControls.Visible     = false;
                CreateAllCompleted.Visible = true;
            }
        }
Beispiel #4
0
        public CountryRegion GetByID(string _countryRegionCode)
        {
            CountryRegionDAC _countryRegionComponent = new CountryRegionDAC();
            IDataReader      reader         = _countryRegionComponent.GetByIDCountryRegion(_countryRegionCode);
            CountryRegion    _countryRegion = null;

            while (reader.Read())
            {
                _countryRegion = new CountryRegion();
                if (reader["CountryRegionCode"] != DBNull.Value)
                {
                    _countryRegion.CountryRegionCode = Convert.ToString(reader["CountryRegionCode"]);
                }
                if (reader["Name"] != DBNull.Value)
                {
                    _countryRegion.Name = Convert.ToString(reader["Name"]);
                }
                if (reader["ModifiedDate"] != DBNull.Value)
                {
                    _countryRegion.ModifiedDate = Convert.ToDateTime(reader["ModifiedDate"]);
                }
                _countryRegion.NewRecord = false;
            }
            reader.Close();
            return(_countryRegion);
        }
        // GET: /Edit
        public ActionResult Edit(int id)
        {
            //Check Exists
            CountryRegion countryRegion = new CountryRegion();

            countryRegion = countryRegionRepository.GetCountryRegion(id);
            if (countryRegion == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }
            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToReferenceInfo())
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }
            CountryRepository countryRepository = new CountryRepository();
            SelectList        countriesList     = new SelectList(countryRepository.GetAllCountries().ToList(), "CountryCode", "CountryName");

            ViewData["Countries"] = countriesList;

            return(View(countryRegion));
        }
        ///<summary>
        ///  Returns a Typed CountryRegionCurrency Entity with mock values.
        ///</summary>
        static public CountryRegionCurrency CreateMockInstance_Generated(TransactionManager tm)
        {
            CountryRegionCurrency mock = new CountryRegionCurrency();

            mock.ModifiedDate = TestUtility.Instance.RandomDateTime();

            //OneToOneRelationship
            CountryRegion mockCountryRegionByCountryRegionCode = CountryRegionTest.CreateMockInstance(tm);

            DataRepository.CountryRegionProvider.Insert(tm, mockCountryRegionByCountryRegionCode);
            mock.CountryRegionCode = mockCountryRegionByCountryRegionCode.CountryRegionCode;
            //OneToOneRelationship
            Currency mockCurrencyByCurrencyCode = CurrencyTest.CreateMockInstance(tm);

            DataRepository.CurrencyProvider.Insert(tm, mockCurrencyByCurrencyCode);
            mock.CurrencyCode = mockCurrencyByCurrencyCode.CurrencyCode;

            // create a temporary collection and add the item to it
            TList <CountryRegionCurrency> tempMockCollection = new TList <CountryRegionCurrency>();

            tempMockCollection.Add(mock);
            tempMockCollection.Remove(mock);


            return((CountryRegionCurrency)mock);
        }
        public async Task <IActionResult> Edit(string id, [Bind("CountryRegionCode,Name,ModifiedDate")] CountryRegion countryRegion)
        {
            if (id != countryRegion.CountryRegionCode)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(countryRegion);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CountryRegionExists(countryRegion.CountryRegionCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(countryRegion));
        }
        public IActionResult DapperTransactionalInsert()
        {
            using (IDbConnection db = new SqlConnection(_configuration.GetConnectionString("DefaultConnection")))
            {
                if (db.State != ConnectionState.Open)
                {
                    db.Open();
                }

                using (var transaction = db.BeginTransaction())
                {
                    string sql = @"INSERT INTO Person.StateProvince(StateProvinceCode, Name)
								Values(@StateProvinceCode, @Name);"                                ;

                    StateProvince stateProvince = new StateProvince {
                        StateProvinceCode = "96", Name = "Pisa"
                    };
                    db.Execute(sql, stateProvince, transaction);


                    CountryRegion countryRegion = new CountryRegion {
                        Name = "Country Name", ModifiedDate = DateTime.Now
                    };
                    sql = @"INSERT INTO [Person].[CountryRegion] (Name, ModifiedDate)
							Values(@Name, @ModifiedDate);"                            ;
                    db.Execute(sql, countryRegion, transaction);

                    transaction.Commit();
                }
            }
            return(Ok());
        }
        protected void BtnCreate_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Country country;

                if (!string.IsNullOrEmpty(TxtName.Text))
                {
                    country = new Country(StoreId, TxtName.Text, long.Parse(DrpCurrencies.SelectedValue));
                    country.Save();
                }
                else
                {
                    DefaultCountry defaultCountry = CountryService.Instance.GetDefaultCountries().First(c => c.Code == DrpCountries.SelectedValue);

                    country = new Country(StoreId, defaultCountry.Name, long.Parse(DrpCurrencies.SelectedValue))
                    {
                        RegionCode = defaultCountry.Code
                    };

                    country.Save();

                    foreach (Region region in defaultCountry.Regions)
                    {
                        CountryRegion countryRegion = new CountryRegion(StoreId, region.Name, country.Id)
                        {
                            RegionCode = region.Code
                        };
                        countryRegion.Save();
                    }
                }
            }
        }
        /// <summary>
        /// Deep load all CountryRegion children.
        /// </summary>
        private void Step_03_DeepLoad_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                int count = -1;
                mock           = CreateMockInstance(tm);
                mockCollection = DataRepository.CountryRegionProvider.GetPaged(tm, 0, 10, out count);

                DataRepository.CountryRegionProvider.DeepLoading += new EntityProviderBaseCore <CountryRegion, CountryRegionKey> .DeepLoadingEventHandler(
                    delegate(object sender, DeepSessionEventArgs e)
                {
                    if (e.DeepSession.Count > 3)
                    {
                        e.Cancel = true;
                    }
                }
                    );

                if (mockCollection.Count > 0)
                {
                    DataRepository.CountryRegionProvider.DeepLoad(tm, mockCollection[0]);
                    System.Console.WriteLine("CountryRegion instance correctly deep loaded at 1 level.");

                    mockCollection.Add(mock);
                    // DataRepository.CountryRegionProvider.DeepSave(tm, mockCollection);
                }

                //normally one would commit here
                //tm.Commit();
                //IDisposable will Rollback Transaction since it's left uncommitted
            }
        }
        public ActionResult Edit(int id, FormCollection collection)
        {
            //Get Item From Database
            CountryRegion countryRegion = countryRegionRepository.GetCountryRegion(id);

            //Check Exists
            if (countryRegion == null)
            {
                ViewData["ActionMethod"] = "EditPost";
                return(View("RecordDoesNotExistError"));
            }
            //AccessRights
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToReferenceInfo())
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }
            //Update Item from Form
            try
            {
                UpdateModel(countryRegion);
            }
            catch
            {
                string n = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        n += error.ErrorMessage;
                    }
                }
                ViewData["Message"] = "ValidationError : " + n;
                return(View("Error"));
            }

            //Database Update
            try
            {
                countryRegionRepository.Update(countryRegion);
            }
            catch (SqlException ex)
            {
                //Versioning Error
                if (ex.Message == "SQLVersioningError")
                {
                    ViewData["ReturnURL"] = "/CountryRegion.mvc/Edit/" + countryRegion.CountryRegionId.ToString();
                    return(View("VersionError"));
                }

                //Generic Error
                ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details";
                return(View("Error"));
            }

            //Success
            return(RedirectToAction("List"));
        }
        //[Authorize(Roles = nameof(PermissionProvider.AddArea))]
        public HttpResponseMessage Create(HttpRequestMessage request, CountryRegion countryRegion)
        {
            return(CreateHttpResponse(request, () =>
            {
                try
                {
                    HttpResponseMessage reponse = null;
                    if (!ModelState.IsValid)
                    {
                        reponse = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                    }
                    else
                    {
                        _countryRegionService.Add(countryRegion);

                        reponse = request.CreateResponse(HttpStatusCode.Created, countryRegion);
                    }
                    return reponse;
                }
                catch (NameDuplicatedException dex)
                {
                    return request.CreateErrorResponse(HttpStatusCode.Conflict, dex.Message);
                }
            }));
        }
Beispiel #13
0
        public void GetCountryRegionByNameTest()
        {
            var           context       = new Entities();
            CountryRegion countryRegion = new CountryRegion(context);
            var           cr            = countryRegion.GetCountryRegionByName("Andorra");

            Assert.AreEqual("Andorra", cr.Name);
        }
Beispiel #14
0
        private async void cboRegion_SelectedIndexChanged(object sender, EventArgs e)
        {
            CountryRegion reg = (CountryRegion)cboRegion.SelectedItem;

            cityList = await API.GetAllCities(reg);

            cboCity.DataSource = cityList;
        }
Beispiel #15
0
        ///<summary>
        ///  Update the Typed CountryRegion Entity with modified mock values.
        ///</summary>
        static public void UpdateMockInstance(TransactionManager tm, CountryRegion mock)
        {
            CountryRegionTest.UpdateMockInstance_Generated(tm, mock);

            // make any alterations necessary
            // (i.e. for DB check constraints, special test cases, etc.)
            SetSpecialTestData(mock);
        }
        protected void BtnCreate_Click( object sender, EventArgs e )
        {
            if ( Page.IsValid ) {
            CountryRegion countryRegion = new CountryRegion( StoreId, TxtName.Text, _countryId );
            countryRegion.Save();

            Redirect( WebUtils.GetPageUrl( Constants.Pages.EditCountryRegion ) + "?id=" + countryRegion.Id + "&storeId=" + countryRegion.StoreId );
              }
        }
Beispiel #17
0
        public override int GetHashCode()
        {
            int hash = 0;

            if (!string.IsNullOrWhiteSpace(AddressLine))
            {
                hash ^= AddressLine.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(AdminDistrict))
            {
                hash ^= AdminDistrict.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(AdminDistrict2))
            {
                hash ^= AdminDistrict2.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(CountryRegion))
            {
                hash ^= CountryRegion.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(FormattedAddress))
            {
                hash ^= FormattedAddress.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(Locality))
            {
                hash ^= Locality.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(PostalCode))
            {
                hash ^= PostalCode.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(PostalTown))
            {
                hash ^= PostalTown.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(Landmark))
            {
                hash ^= Landmark.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(Neighborhood))
            {
                hash ^= Neighborhood.GetHashCode();
            }

            return(hash);
        }
        /// <summary>
        /// Check the foreign key dal methods.
        /// </summary>
        private void Step_10_FK_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                CountryRegion entity = CreateMockInstance(tm);
                bool          result = DataRepository.CountryRegionProvider.Insert(tm, entity);

                Assert.IsTrue(result, "Could Not Test FK, Insert Failed");
            }
        }
        public static CountryRegion Parse(SpeedrunComClient client, dynamic regionElement)
        {
            var region = new CountryRegion();

            region.Code = regionElement.code as string;
            region.Name = regionElement.names.international as string;
            region.JapaneseName = regionElement.names.japanese as string;

            return region;
        }
Beispiel #20
0
        //Add to DB
        public void Add(CountryRegion countryRegion)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_InsertCountryRegion_v1(
                countryRegion.CountryRegionName,
                countryRegion.CountryCode,
                adminUserGuid
                );
        }
Beispiel #21
0
        public static CountryRegion Parse(SpeedrunComClient client, dynamic regionElement)
        {
            var region = new CountryRegion();

            region.Code         = regionElement.code as string;
            region.Name         = regionElement.names.international as string;
            region.JapaneseName = regionElement.names.japanese as string;

            return(region);
        }
 public ActionResult Edit([Bind(Include = "CountryRegionCode,Name,ModifiedDate,isDeleted")] CountryRegion countryRegion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(countryRegion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(countryRegion));
 }
Beispiel #23
0
        public CountryRegionBuilder WithTestValues()
        {
            countryRegion = new CountryRegion
            {
                CountryRegionCode = "US",
                Name = "United States"
            };

            return(this);
        }
Beispiel #24
0
        //Delete From DB
        public void Delete(CountryRegion countryRegion)
        {
            string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0];

            db.spDesktopDataAdmin_DeleteCountryRegion_v1(
                countryRegion.CountryRegionId,
                adminUserGuid,
                countryRegion.VersionNumber
                );
        }
        protected void BtnCreate_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                CountryRegion countryRegion = new CountryRegion(StoreId, TxtName.Text, _countryId);
                countryRegion.Save();

                Redirect(WebUtils.GetPageUrl(Constants.Pages.EditCountryRegion) + "?id=" + countryRegion.Id + "&storeId=" + countryRegion.StoreId);
            }
        }
        public ActionResult Create([Bind(Include = "CountryRegionCode,Name,ModifiedDate,isDeleted")] CountryRegion countryRegion)
        {
            if (ModelState.IsValid)
            {
                db.CountryRegions.Add(countryRegion);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(countryRegion));
        }
        public async Task <IActionResult> Create([Bind("CountryRegionCode,Name,ModifiedDate")] CountryRegion countryRegion)
        {
            if (ModelState.IsValid)
            {
                _context.Add(countryRegion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(countryRegion));
        }
        // GET: /Create
        public ActionResult Create()
        {
            CountryRepository countryRepository = new CountryRepository();
            SelectList        countriesList     = new SelectList(countryRepository.GetAllCountries().ToList(), "CountryCode", "CountryName");

            ViewData["Countries"] = countriesList;

            CountryRegion countryRegion = new CountryRegion();

            return(View(countryRegion));
        }
        /// <summary>
        /// Test methods exposed by the EntityHelper class.
        /// </summary>
        private void Step_20_TestEntityHelper_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                mock = CreateMockInstance(tm);

                CountryRegion entity = mock.Copy() as CountryRegion;
                entity = (CountryRegion)mock.Clone();
                Assert.IsTrue(CountryRegion.ValueEquals(entity, mock), "Clone is not working");
            }
        }
        public virtual BOCountryRegion MapEFToBO(
            CountryRegion ef)
        {
            var bo = new BOCountryRegion();

            bo.SetProperties(
                ef.CountryRegionCode,
                ef.ModifiedDate,
                ef.Name);
            return(bo);
        }
        public virtual CountryRegion MapBOToEF(
            BOCountryRegion bo)
        {
            CountryRegion efCountryRegion = new CountryRegion();

            efCountryRegion.SetProperties(
                bo.CountryRegionCode,
                bo.ModifiedDate,
                bo.Name);
            return(efCountryRegion);
        }
        // PUT api/awbuildversion/5
        public void Put(CountryRegion value)
        {
            var GetActionType = Request.Headers.Where(x => x.Key.Equals("ActionType")).FirstOrDefault();

            if (GetActionType.Key != null)
            {
                if (GetActionType.Value.ToList()[0].Equals("DELETE"))
                    adventureWorks_BC.CountryRegionDelete(value);
                if (GetActionType.Value.ToList()[0].Equals("UPDATE"))
                    adventureWorks_BC.CountryRegionUpdate(value);
            }
        }
Beispiel #33
0
        ///<summary>
        ///  Returns a Typed CountryRegion Entity with mock values.
        ///</summary>
        static public CountryRegion CreateMockInstance(TransactionManager tm)
        {
            // get the default mock instance
            CountryRegion mock = CountryRegionTest.CreateMockInstance_Generated(tm);

            // make any alterations necessary
            // (i.e. for DB check constraints, special test cases, etc.)
            SetSpecialTestData(mock);

            // return the modified object
            return(mock);
        }
		private StateProvince GivenStateProvince(string code, string name, bool isOnlyStateProvince, CountryRegion country, SalesTerritory territory)
		{
			var state = new StateProvince
				{
					Code = code,
					Name = name,
					IsOnlyStateProvince = isOnlyStateProvince,
					SalesTerritory = territory,
					Country = country
				};

			Inject(state);

			return state;
		}
        public void CountryRegionTest()
        {
            var country = new CountryRegion
                              {
                                  Code = "TCR",
                                  Name = "Test TCR"
                              };

            Inject(country);

            var returnedCountry = ReadFirstOrDefault<CountryRegion>(x => x.Code == "TCR");
            Assert.IsNotNull(returnedCountry);
			Assert.AreEqual(returnedCountry.Code, country.Code);
			Assert.AreEqual(returnedCountry.Name, country.Name);
        }
 /// <summary>
 /// Create a new CountryRegion object.
 /// </summary>
 /// <param name="countryRegionCode">Initial value of CountryRegionCode.</param>
 /// <param name="name">Initial value of Name.</param>
 /// <param name="modifiedDate">Initial value of ModifiedDate.</param>
 public static CountryRegion CreateCountryRegion(string countryRegionCode, string name, global::System.DateTime modifiedDate)
 {
     CountryRegion countryRegion = new CountryRegion();
     countryRegion.CountryRegionCode = countryRegionCode;
     countryRegion.Name = name;
     countryRegion.ModifiedDate = modifiedDate;
     return countryRegion;
 }
 // POST api/awbuildversion
 public void Post(CountryRegion value)
 {
     adventureWorks_BC.CountryRegionAdd(value);
 }
 /// <summary>
 /// There are no comments for CountryRegion in the schema.
 /// </summary>
 public void AddToCountryRegion(CountryRegion countryRegion)
 {
     base.AddObject("CountryRegion", countryRegion);
 }
 public static CountryRegion CreateCountryRegion(string countryCode, string regionCode, int sortOrder)
 {
     CountryRegion countryRegion = new CountryRegion();
     countryRegion.CountryCode = countryCode;
     countryRegion.RegionCode = regionCode;
     countryRegion.SortOrder = sortOrder;
     return countryRegion;
 }