Example #1
0
 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;
     }
 }
Example #4
0
        public static void InitializeDbForTests(AddressContext db)
        {
            List <Domain.Address> addresses = GetSeedingAddresses();

            db.Addresses.AddRange(addresses);
            db.SaveChanges();
        }
Example #5
0
 public void Post(Address value)
 {
     using (var dataContext = new AddressContext())
     {
         dataContext.Addresses.Add(value);
         dataContext.SaveChanges();
     }
 }
Example #6
0
 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();
     }
 }
Example #7
0
 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));
        }
Example #9
0
        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();
            }
        }
Example #10
0
 public void Add(List <City> citys)
 {
     if (citys == null || citys.Count == 0)
     {
         return;
     }
     using (var db = new AddressContext())
     {
         db.CityInfo.AddRange(citys);
         db.SaveChanges();
     }
 }
Example #11
0
 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();
            }
        }
Example #13
0
 public void Delete(County county)
 {
     if (county == null)
     {
         return;
     }
     using (var db = new AddressContext())
     {
         db.Remove(county);
         db.SaveChanges();
     }
 }
Example #14
0
        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();
                }
            }
        }
Example #15
0
 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();
     }
 }
Example #16
0
 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();
     }
 }
Example #17
0
        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();
            }
        }
Example #18
0
        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();
            }
        }
Example #19
0
        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();
            }
        }
Example #20
0
        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();
            }
        }
Example #21
0
        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();
        }
Example #22
0
        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();
        }
Example #23
0
        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();
        }
Example #24
0
 public void Commit()
 {
     _context.SaveChanges();
 }
 public Domain.Model.Address Insert(Domain.Model.Address obj)
 {
     _context.Addresses.Add(obj);
     _context.SaveChanges();
     return(obj);
 }
Example #26
0
 public void Save()
 {
     _dbContext.SaveChanges();
 }
 public void Create(Address.Domain.Address address)
 {
     _addressContext.Addresses.Add(address);
     _addressContext.SaveChanges();
 }
Example #28
0
 public int?Add(Address entity)
 {
     _addressContext.Addresses.Add(entity);
     _addressContext.SaveChanges();
     return(entity.ID);
 }
 public void AddAddress(Address address)
 {
     _db.Add(address);
     _db.SaveChanges();
 }