public ActionResult Create(Address address) { if (ModelState.IsValid) { _ctxAddress.Addresses.Add(address); _ctxAddress.SaveChanges(); return(RedirectToAction("Index")); } return(View(address)); }
public ActionResult Create([Bind(Include = "StreetPrefixId,Prefix")] StreetPrefix streetPrefix) { if (ModelState.IsValid) { db.StreetPrefixes.Add(streetPrefix); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(streetPrefix)); }
public virtual void Insert(TEntity entity) { try { context.Set <TEntity>().Add(entity); context.SaveChanges(); } catch (Exception ex) { throw ex; } }
public static void InitializeDbForTests(AddressContext db) { List <Domain.Address> addresses = GetSeedingAddresses(); db.Addresses.AddRange(addresses); db.SaveChanges(); }
public void Post(Address value) { using (var dataContext = new AddressContext()) { dataContext.Addresses.Add(value); dataContext.SaveChanges(); } }
public void Delete(int cityCode) { using (var db = new AddressContext()) { var city = db.CityInfo.Include(y => y.County).First(x => x.CityCode.Equals(cityCode)); db.Remove(city); db.SaveChanges(); } }
public ActionResult Add([Bind(Include = "customerNum,dob,currentDate,fullName,city,st,zip,street")] Address address) { if (ModelState.IsValid) { db.Addresses.Add(address); db.SaveChanges(); return(RedirectToAction("List")); } return(View(address)); }
public IHttpActionResult PostAddress(CustomerAddress addressmodel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string userId = User.Identity.GetUserId(); // Debug.WriteLine("*****************************" + userId); addressmodel.Deleted = false; addressmodel.UserId = userId; db.Address.Add(addressmodel); db.SaveChanges(); return(CreatedAtRoute("Save", new { /*id = addressmodel.AddressId */ }, addressmodel)); }
public void ChangeRelationship() { using (var db = new AddressContext()) { var county = db.Countys.Single(x => x.FullName.Equals("Thanh Trì")); var city = db.CityInfo.Single(x => x.CityCode == 2); county.City = city; db.SaveChanges(); } }
public void Add(List <City> citys) { if (citys == null || citys.Count == 0) { return; } using (var db = new AddressContext()) { db.CityInfo.AddRange(citys); db.SaveChanges(); } }
public void DeleteRange(List <City> citys) { if (citys == null || citys.Count == 0) { return; } using (var db = new AddressContext()) { db.RemoveRange(citys); db.SaveChanges(); } }
public AddressControllerTest() { _dbOptions = new DbContextOptionsBuilder <AddressContext>() .UseInMemoryDatabase(databaseName: "in-memory") .Options; using (var dbContext = new AddressContext(_dbOptions)) { dbContext.AddRange(AddressContextDbSeed.GetData()); dbContext.SaveChanges(); } }
public void Delete(County county) { if (county == null) { return; } using (var db = new AddressContext()) { db.Remove(county); db.SaveChanges(); } }
public void Delete(int id) { using (var dataContext = new AddressContext()) { var updateValue = dataContext.Addresses.FirstOrDefault(item => item.AddressId == id); if (null != updateValue) { dataContext.Addresses.Remove(updateValue); dataContext.SaveChanges(); } } }
public void Update(City cityNew) { if (cityNew == null) { return; } using (var db = new AddressContext()) { var cityOld = db.CityInfo .Single(x => x.CityCode.Equals(cityNew.CityCode)); cityOld = cityNew; db.SaveChanges(); } }
public void Update(County countyNew) { if (countyNew == null) { return; } using (var db = new AddressContext()) { var cityOld = db.Countys .Single(x => x.CountyId.Equals(countyNew.CountyId)); cityOld = countyNew; db.SaveChanges(); } }
static void Main(string[] args) { var phone = new Phone { EntryId = 1, Number = "1234567", Type = 0 }; using (var db = new AddressContext()) { db.Phones.Add(phone); db.SaveChanges(); } }
public void RemoveRelationship() { using (var db = new AddressContext()) { var city = db.CityInfo //.Include(x => x.County.Where(x => x.Equals.Equals...)) .Include(x => x.County) .First(x => x.CityCode == 2); var county = city.County.First(countys => countys.FullName.Equals("Thanh Trì")); city.County.Remove(county); db.SaveChanges(); } }
public void Put(int id, Address value) { using (var dataContext = new AddressContext()) { var updateValue = dataContext.Addresses.FirstOrDefault(item => item.AddressId == id); updateValue.AddressLineOne = value.AddressLineOne; updateValue.AddressLineTwo = value.AddressLineTwo; updateValue.City = value.City; updateValue.AddressState = value.AddressState; updateValue.Zip = value.Zip; updateValue.Country = value.Country; dataContext.SaveChanges(); } }
public void AddRelatedEntity() { using (var db = new AddressContext()) { var county = new County { FullName = "Thanh Trì", IsDelete = false, }; var city = db.CityInfo .Include(x => x.County) .First(); city.County.Add(county); db.SaveChanges(); } }
public void GetAddresses() { //Arrange var options = new DbContextOptionsBuilder <AddressContext>().UseInMemoryDatabase(databaseName: "Addresses").Options; var context = new AddressContext(options); context.Addresses.AddRange(new Address[] { a, b, c }); context.SaveChanges(); var repository = new AddressRepository(context); // Act var output = repository.GetAddresses(); //Assert Assert.AreEqual(3, output.Count()); context.Database.EnsureDeleted(); }
public void TestValidDeleteAddressById() { //Arrange var options = new DbContextOptionsBuilder <AddressContext>().UseInMemoryDatabase(databaseName: "Addresses").Options; var context = new AddressContext(options); context.Addresses.Add(a); context.SaveChanges(); var repository = new AddressRepository(context); // Act repository.DeleteAddressById(1); //Assert Assert.AreEqual(0, context.Addresses.Count()); context.Database.EnsureDeleted(); }
public void CreatePointTest() { var allAddresses = _target.Addresses .Where(x => x.Point == null) .ToList(); void UpdateAddressWithPoint(Domain.Model.Address obj) { if (!obj.Latitude.HasValue || !obj.Longitude.HasValue) { return; } obj.Point = new Point(obj.Latitude.Value, obj.Longitude.Value); _target.Attach(obj); _target.Entry(obj).State = EntityState.Modified; } allAddresses.ForEach(UpdateAddressWithPoint); _target.SaveChanges(); }
public void Commit() { _context.SaveChanges(); }
public Domain.Model.Address Insert(Domain.Model.Address obj) { _context.Addresses.Add(obj); _context.SaveChanges(); return(obj); }
public void Save() { _dbContext.SaveChanges(); }
public void Create(Address.Domain.Address address) { _addressContext.Addresses.Add(address); _addressContext.SaveChanges(); }
public int?Add(Address entity) { _addressContext.Addresses.Add(entity); _addressContext.SaveChanges(); return(entity.ID); }
public void AddAddress(Address address) { _db.Add(address); _db.SaveChanges(); }