public ActionResult EditAddress(string street, int postCode, Guid?cityID, Guid?countryID, int form) { Customer person = (Customer)Session["customer"]; ViewBag.CityID = new SelectList(cits.GetActive(), "ID", "CityName", cityID); ViewBag.CountryID = new SelectList(cnts.GetActive(), "ID", "CountryName", countryID); //Address Address adr = new Address(); if (form == 1) { if (person.ShippingAddress != null) { adr = ads.GetByID(person.ShipAddressID); } else { ads.Add(adr); person.ShipAddressID = adr.ID; } } else { if (person.BillingAddress != null) { adr = ads.GetByID(person.BillAddressID); } else { ads.Add(adr); person.BillAddressID = adr.ID; } } adr.Street = street; adr.PostalCode = postCode; //Country Country country = cnts.GetByID(countryID); //City City city = cits.GetByID(cityID); if (city.Country == null) { city.CountryID = countryID; cits.Update(city); } adr.CityID = city.ID; bool success = ads.Update(adr); if (success) { cs.Update(person); } return(RedirectToAction("MyAccount", "Account")); }
public void Save() { if (CheckData()) { AddressService service = new AddressService(); if ((this.DataContext as AddressEntity).Id == -1 && !CheckDoppione()) { if (service.Add(this.DataContext as AddressEntity) == 0) { MessageBox.Show("Salvato!"); this.DataContext = new AddressEntity(); } else { MessageBox.Show("Errore durante il salvataggio!"); } } else { if (service.Update(this.DataContext as AddressEntity) == 0) { MessageBox.Show("Salvato!"); } else { MessageBox.Show("Errore durante il salvataggio!"); } } } }
public void TestInsert() { // Тест добавления адреса - вставки в БД var result = AddressService.Add(new AddressData { Id = Id, FirstName = "Tester", Birthday = new DateTime(1996, 3, 10), Company = "Dizoft", PhoneNumber = "+79094567201", SecondName = "WiRight" }); Assert.AreEqual(1, result); Assert.AreEqual(1, result); /* using (var connection = new OleDbConnection(ConnectionString())) * { * const string query = "select * from Adressbook WHERE Id = @id"; * * using (var command = new OleDbCommand(query, connection)) * { * command.Parameters.AddWithValue("@id", Id); * * connection.Open(); * * result = command.ExecuteNonQuery(); * * Assert.AreEqual(1, result); * } * }*/ }
public void ReturnFalse_WhenNullArgumentIsPassed() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var addressService = new AddressService(mockedUnitOfWork.Object, mockedMapper.Object); //Act & Assert Assert.IsFalse(addressService.Add(null)); }
public ActionResult AddAddre(AddressBiao d) { d.TTime = DateTime.Now; d.XTime = DateTime.Now; d.ZhuangTai = 1; var a = new AddressService(); var s = a.Add(d); return(RedirectToAction("Query")); }
public void Add(Address entity) { try { addressServices.Add(entity); } catch (Exception ex) { throw ex; } }
public void Address_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { AddressService addressService = new AddressService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); int count = 0; if (count == 1) { // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used] } Address address = GetFilledRandomAddress(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = addressService.GetAddressList().Count(); Assert.AreEqual(count, (from c in dbTestDB.Addresses select c).Count()); addressService.Add(address); if (address.HasErrors) { Assert.AreEqual("", address.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, addressService.GetAddressList().Where(c => c == address).Any()); addressService.Update(address); if (address.HasErrors) { Assert.AreEqual("", address.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, addressService.GetAddressList().Count()); addressService.Delete(address); if (address.HasErrors) { Assert.AreEqual("", address.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, addressService.GetAddressList().Count()); } } }
public void ReturnFalse_WhenExceptionOccured() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var addressService = new AddressService(mockedUnitOfWork.Object, mockedMapper.Object); var mockedAddressModel = new Mock <AddressModel>(); //Act mockedUnitOfWork.Setup(x => x.AddressRepository).Throws(new Exception()); //Assert Assert.IsFalse(addressService.Add(mockedAddressModel.Object)); }
public ActionResult Insert(Address item, Guid?id) { item.AppUserID = (Guid)id; bool result = ads.Add(item); if (result) { return(RedirectToAction("Index", new { id = item.AppUserID })); } else { ViewBag.Message = "Kayıt esnasında bir problem oluştu"; } return(View()); }
public void CallMapperMapMethod_WhenInvokedWithValidArgs() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var addressService = new AddressService(mockedUnitOfWork.Object, mockedMapper.Object); var mockedAddressRepository = new Mock <IAddressRepository>(); var mockedAddress = new Mock <Address>(); var mockedAddressModel = new Mock <AddressModel>(); //Act mockedMapper.Setup(x => x.Map <Address>(mockedAddressModel.Object)).Returns(mockedAddress.Object); addressService.Add(mockedAddressModel.Object); //Assert mockedMapper.Verify(x => x.Map <Address>(mockedAddressModel.Object), Times.Once); }
public void ExecuteMethodAndReturnTrue_WhenInvokedWithValidArgs() { //Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedMapper = new Mock <IMapper>(); var addressService = new AddressService(mockedUnitOfWork.Object, mockedMapper.Object); var mockedAddressRepository = new Mock <IAddressRepository>(); var mockedAddress = new Mock <Address>(); var mockedAddressModel = new Mock <AddressModel>(); //Act mockedMapper.Setup(x => x.Map <Address>(mockedAddressModel.Object)).Returns(mockedAddress.Object); mockedUnitOfWork.Setup(x => x.AddressRepository).Returns(mockedAddressRepository.Object); mockedAddressRepository.Setup(x => x.Update(mockedAddress.Object)); mockedUnitOfWork.Setup(x => x.SaveChanges()); //Assert Assert.IsTrue(addressService.Add(mockedAddressModel.Object)); }
public IHttpActionResult Post([FromBody] Address address, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { AddressService addressService = new AddressService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!addressService.Add(address)) { return(BadRequest(String.Join("|||", address.ValidationResults))); } else { address.ValidationResults = null; return(Created <Address>(new Uri(Request.RequestUri, address.AddressID.ToString()), address)); } } }
public ActionResult Insert(DealerAddressVM item) { ViewBag.CityID = new SelectList(cits.GetActive(), "ID", "CityName", item.CityID); ViewBag.CountryID = new SelectList(cnts.GetActive(), "ID", "CountryName", item.CountryID); if (ModelState.IsValid) { Dealer d = new Dealer(); d.Name = item.Name; d.MainPhone = item.MainPhone; Address a = new Address(); a.Street = item.Street; a.PostalCode = item.PostalCode; a.CityID = item.CityID; City c = cits.GetByID(item.CityID); if (c.Country == null) { c.CountryID = item.CountryID; cits.Update(c); } adrs.Add(a); d.AddressID = a.ID; bool sonuc = ds.Add(d); if (sonuc) { return(RedirectToAction("Index")); } } else { ViewBag.Message = "Invalid format."; } return(View()); }
public ActionResult Insert(Address item) { ViewBag.ProvinceID = new SelectList(ilservice.GetActive(), "ID", "ProvinceName", item.ProvinceID); ViewBag.CountryID = new SelectList(ilceservice.GetActive(), "ID", "CountryName", item.CountryID); ViewBag.DistrictID = new SelectList(semtservice.GetActive(), "ID", "DistrictName", item.DistrictID); ViewBag.RestaurantID = new SelectList(rs.GetActive(), "ID", "Name", item.RestaurantID); if (ModelState.IsValid) { bool sonuc = adresservice.Add(item); if (sonuc) { return(RedirectToAction("Index")); } else { ViewBag.Mesaj = "Semt Ekleme işlemi Sirasinda bir hata olustu.Lütfen daha sonra tekrar deneyin."; } } else { ViewBag.Mesaj = "Girmiş oldugunuz bilgiler hatali formattta veya eksiktir.Lütfen girmeye çaliştiğiniz verileri kontrol edin."; } return(View()); }
public ActionResult <AddressModel> AddAddress([FromBody] AddressModel address) { return(addressService.Add(address)); }
// POST: api/Address public Response AddAddress([FromBody] Address addr) { return(addrServ.Add(addr)); }
public void Address_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { AddressService addressService = new AddressService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); int count = 0; if (count == 1) { // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used] } count = addressService.GetAddressList().Count(); Address address = GetFilledRandomAddress(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // address.AddressID (Int32) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.AddressID = 0; addressService.Update(address); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "AddressID"), address.ValidationResults.FirstOrDefault().ErrorMessage); address = null; address = GetFilledRandomAddress(""); address.AddressID = 10000000; addressService.Update(address); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "Address", "AddressID", address.AddressID.ToString()), address.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Address)] // address.AddressTVItemID (Int32) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.AddressTVItemID = 0; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "AddressTVItemID", address.AddressTVItemID.ToString()), address.ValidationResults.FirstOrDefault().ErrorMessage); address = null; address = GetFilledRandomAddress(""); address.AddressTVItemID = 1; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "AddressTVItemID", "Address"), address.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // address.AddressType (AddressTypeEnum) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.AddressType = (AddressTypeEnum)1000000; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "AddressType"), address.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Country)] // address.CountryTVItemID (Int32) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.CountryTVItemID = 0; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "CountryTVItemID", address.CountryTVItemID.ToString()), address.ValidationResults.FirstOrDefault().ErrorMessage); address = null; address = GetFilledRandomAddress(""); address.CountryTVItemID = 1; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "CountryTVItemID", "Country"), address.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Province)] // address.ProvinceTVItemID (Int32) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.ProvinceTVItemID = 0; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ProvinceTVItemID", address.ProvinceTVItemID.ToString()), address.ValidationResults.FirstOrDefault().ErrorMessage); address = null; address = GetFilledRandomAddress(""); address.ProvinceTVItemID = 1; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "ProvinceTVItemID", "Province"), address.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Municipality)] // address.MunicipalityTVItemID (Int32) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.MunicipalityTVItemID = 0; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MunicipalityTVItemID", address.MunicipalityTVItemID.ToString()), address.ValidationResults.FirstOrDefault().ErrorMessage); address = null; address = GetFilledRandomAddress(""); address.MunicipalityTVItemID = 1; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "MunicipalityTVItemID", "Municipality"), address.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [StringLength(200))] // address.StreetName (String) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.StreetName = GetRandomString("", 201); Assert.AreEqual(false, addressService.Add(address)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "StreetName", "200"), address.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, addressService.GetAddressList().Count()); // ----------------------------------- // Is Nullable // [StringLength(50))] // address.StreetNumber (String) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.StreetNumber = GetRandomString("", 51); Assert.AreEqual(false, addressService.Add(address)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "StreetNumber", "50"), address.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, addressService.GetAddressList().Count()); // ----------------------------------- // Is Nullable // [CSSPEnumType] // address.StreetType (StreetTypeEnum) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.StreetType = (StreetTypeEnum)1000000; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "StreetType"), address.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [StringLength(11, MinimumLength = 6)] // address.PostalCode (String) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.PostalCode = GetRandomString("", 5); Assert.AreEqual(false, addressService.Add(address)); Assert.AreEqual(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "PostalCode", "6", "11"), address.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, addressService.GetAddressList().Count()); address = null; address = GetFilledRandomAddress(""); address.PostalCode = GetRandomString("", 12); Assert.AreEqual(false, addressService.Add(address)); Assert.AreEqual(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "PostalCode", "6", "11"), address.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, addressService.GetAddressList().Count()); // ----------------------------------- // Is Nullable // [StringLength(200, MinimumLength = 10)] // address.GoogleAddressText (String) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.GoogleAddressText = GetRandomString("", 9); Assert.AreEqual(false, addressService.Add(address)); Assert.AreEqual(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "GoogleAddressText", "10", "200"), address.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, addressService.GetAddressList().Count()); address = null; address = GetFilledRandomAddress(""); address.GoogleAddressText = GetRandomString("", 201); Assert.AreEqual(false, addressService.Add(address)); Assert.AreEqual(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "GoogleAddressText", "10", "200"), address.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, addressService.GetAddressList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // address.LastUpdateDate_UTC (DateTime) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.LastUpdateDate_UTC = new DateTime(); addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), address.ValidationResults.FirstOrDefault().ErrorMessage); address = null; address = GetFilledRandomAddress(""); address.LastUpdateDate_UTC = new DateTime(1979, 1, 1); addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), address.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // address.LastUpdateContactTVItemID (Int32) // ----------------------------------- address = null; address = GetFilledRandomAddress(""); address.LastUpdateContactTVItemID = 0; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", address.LastUpdateContactTVItemID.ToString()), address.ValidationResults.FirstOrDefault().ErrorMessage); address = null; address = GetFilledRandomAddress(""); address.LastUpdateContactTVItemID = 1; addressService.Add(address); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), address.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // address.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // address.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }