예제 #1
0
 /// <summary>
 ///     Updates the Address of a Contact.
 ///     Needs custId to update search index.
 /// </summary>
 /// <param name="custId"></param>
 /// <param name="address"></param>
 public void UpdateContactAddress(int custId, Model.Address address)
 {
     ThrowIfNull(address);
     ValidateAndThrow(address, new AddressValidator());
     Context.Addresses.Attach(address);
     Context.SetEntityState(address, EntityState.Modified);
     Context.SaveChanges();
 }
예제 #2
0
 public Person()
 {
     Address = new Address();
       Info = new PersonalInfo
       {
     Weight = new Measurement(),
     Height = new Measurement()
       };
 }
예제 #3
0
        /// <summary>
        ///     Creates an Address for a Contact.
        /// </summary>
        /// <param name="custId"></param>
        /// <param name="contactId"></param>
        /// <param name="addr"></param>
        /// <returns>Returns the id of the new Address.</returns>
        public int CreateContactAddress(int custId, int contactId, Model.Address addr)
        {
            ThrowIfNull(addr);
            ValidateAndThrow(addr, new AddressValidator());
            var contact = Spoof <Contact>(contactId);

            Context.Contacts.Attach(contact);
            Context.Addresses.Add(addr);
            contact.Address = addr;
            Context.SaveChanges();
            return(addr.Id);
        }
예제 #4
0
        public void DeleteAddress(int customerId, int addressId)
        {
            ThrowIfNull(addressId);
            ThrowIfNull(customerId);
            var caToRemove = Context.CustomerAddresses.Where(c => c.CustomerId == customerId && c.AddressId == addressId).ToArray();

            Context.CustomerAddresses.RemoveRange(caToRemove);

            Model.Address obj = new Model.Address {
                Id = addressId
            };
            Context.Addresses.Attach(obj);
            Context.Addresses.Remove(obj);

            Context.SaveChanges();

            var customerAddresses = Context.Customers
                                    .Where(c => c.Id == customerId)
                                    .SelectMany(c => c.CustomerAddresses)
                                    .ToArray();

            EnsureOneAddressIsPrimary(customerAddresses);
        }
 /// <summary>
 ///     Updates an Address of a User.
 /// </summary>
 public new void UpdateAddress(Model.Address address)
 {
     base.UpdateAddress(address);
 }
 /// <summary>
 ///     Creates new Address and associates it to CustomerLocation
 /// </summary>
 /// <param name="custLocId"></param>
 /// <param name="address"></param>
 /// <returns></returns>
 public CreateAddressResult CreateAddress(int custLocId, Model.Address address)
 {
     return(base.CreateAddress <CustomerLocation>(custLocId, address));
 }
예제 #7
0
        private void InsertAddress(string hotelId, string hotelCode, IList <OTA_HotelDescriptiveInfoRS.HotelDescriptiveContentsLocalType.HotelDescriptiveContentLocalType.HotelInfoLocalType.AddressLocalType> Address)
        {
            if (Address != null)
            {
                using (var context = new TravelDBContext())
                {
                    //using (TransactionScope tran = new TransactionScope())
                    {
                        EfRepository <Address>          addressContext          = new EfRepository <Address>(context);
                        EfRepository <AddressExtension> addressExtensionContext = new EfRepository <AddressExtension>(context);
                        EfRepository <Zone>             zoonContext             = new EfRepository <Zone>(context);
                        EfRepository <ZoneHotelMapping> zonehoteMappingContext  = new EfRepository <ZoneHotelMapping>(context);

                        var addressList = (from a in addressContext.Table where a.HotelID == hotelId select a).ToList();

                        if (addressList.Count > 0)
                        {
                            foreach (var al in addressList)
                            {
                                var addressExtension = addressExtensionContext.Table.Where(a => a.AddressID.Value == al.Id).ToList();
                                if (addressExtension.Count > 0)
                                {
                                    addressExtensionContext.Delete(addressExtension);
                                    LoggerHelper(hotelCode, "Hotel AddressExtensions Deleted");
                                }

                                var zoonhoteMapping = zonehoteMappingContext.Table.Where(z => z.HotelID == hotelId).ToList();
                                if (zoonhoteMapping.Count > 0)
                                {
                                    zonehoteMappingContext.Delete(zoonhoteMapping);
                                    LoggerHelper(hotelCode, "Hotel Zoon Deleted");
                                }
                            }


                            addressContext.Delete(addressList);
                            LoggerHelper(hotelCode, "Hotel Address Deleted");
                        }



                        foreach (var item in Address)
                        {
                            string addressLine = item.AddressLine;
                            string cityName    = item.CityName;
                            string postalCode  = item.PostalCode;

                            Address address = new Model.Address();
                            address.HotelID        = hotelId;
                            address.AddressLine    = addressLine;
                            address.CityName       = cityName;
                            address.PostalCode     = postalCode;
                            address.LastModifyTime = DateTime.Now;

                            addressContext.Insert(address);

                            LoggerHelper(hotelCode, addressLine);

                            int addressPK = address.Id;



                            var zone = item.Zone;
                            if (zone != null)
                            {
                                foreach (var z in zone)
                                {
                                    int  zCode          = Convert.ToInt32(z.ZoneCode);
                                    bool checkZoneExits = zoonContext.Table.Where(zm => zm.Id == zCode).Any();
                                    if (!checkZoneExits)
                                    {
                                        Zone zm = new Zone();
                                        zm.Id             = zCode;
                                        zm.Name           = z.ZoneName;
                                        zm.LastMofifyTime = DateTime.Now;
                                        zoonContext.Insert(zm);

                                        LoggerHelper(hotelCode, "zoon:" + z.ZoneName + "deleted");
                                    }

                                    ZoneHotelMapping zhm = new ZoneHotelMapping();
                                    zhm.HotelID        = hotelId;
                                    zhm.ZoneID         = zCode;
                                    zhm.LastMofifyTime = DateTime.Now;

                                    zonehoteMappingContext.Insert(zhm);

                                    LoggerHelper(hotelCode, "zoon:" + z.ZoneName);
                                }
                            }

                            var extension = item.TPA_Extensions;
                            if (extension != null && extension.Count > 0)
                            {
                                foreach (var e in extension)
                                {
                                    Console.WriteLine("AddressExternsion :" + e.RoadCross[0].DescriptionText);

                                    AddressExtension ae = new AddressExtension();
                                    ae.AddressID      = addressPK;
                                    ae.Description    = e.RoadCross[0].DescriptionText;
                                    ae.LastModifyTime = DateTime.Now;

                                    addressExtensionContext.Insert(ae);
                                    LoggerHelper(hotelCode, "addressExtension:" + ae.Description + "Inserted");
                                }
                            }
                        }


                        // tran.Complete();
                    }
                }
            }
        }