Пример #1
0
        public async Task <bool> SaveAddress(AddressModel addressModel)
        {
            using (DBContext db = new DBContext())
            {
                DataAccessLibrary.EntityModels.Address address = db.Address.Where
                                                                     (x => x.AddressId == addressModel.AddressId).FirstOrDefault();
                if (address == null)
                {
                    address = new Address()
                    {
                        Street      = addressModel.Street,
                        Number      = addressModel.Number,
                        City        = addressModel.City,
                        State       = addressModel.State,
                        Country     = addressModel.Country,
                        Fk_PersonId = addressModel.Fk_PersonId
                    };
                    db.Address.Add(address);
                }
                else
                {
                    address.Street  = addressModel.Street;
                    address.Number  = addressModel.Number;
                    address.City    = addressModel.City;
                    address.State   = addressModel.State;
                    address.Country = addressModel.Country;
                }

                return(await db.SaveChangesAsync() >= 1);
            }
        }
Пример #2
0
 public async Task <bool> DeleteAddress(int addressId)
 {
     using (DBContext db = new DBContext())
     {
         DataAccessLibrary.EntityModels.Address address = db.Address.Where(x => x.AddressId == addressId).FirstOrDefault();
         if (address != null)
         {
             db.Address.Remove(address);
         }
         return(await db.SaveChangesAsync() >= 1);
     }
 }