public bool CreatePremise(Premise pre, PremiseDetail detail, PermiseDetailForCost cost, PremiseOpenSchedule open)
        {
            try
            {
                _db.Premises.InsertOnSubmit(pre);
                _db.SubmitChanges();
                detail.PremiseID = pre.PremiseID;
                cost.PermiseID = pre.PremiseID;
                open.PremiseID = pre.PremiseID;
                _db.PremiseDetails.InsertOnSubmit(detail);
                _db.PermiseDetailForCosts.InsertOnSubmit(cost);
                _db.PremiseOpenSchedules.InsertOnSubmit(open);
                _db.SubmitChanges();

                return true;
            }
            catch
            {
                return false;
            }
        }
        public PartialViewResult Add(string LocationName, string LocationStatus, string PremisePhone, int? CountryID,
            int? LocationOrganisation, int? MediaContact, int? CateringContact, int? CateringType, int? VisitorParkingSpace,
            int? HostingContact, int? NoOfMeetingRooms, int? PreferredStatus, int? Codings,
            FormCollection collection)
        {
            Premise pre = new Premise();

            pre.LocationName = LocationName;
            pre.PrimaryLocation = collection["PrimaryLocation"] == "1" ? 1 : 0;
            pre.KnownAS = collection["KnownAS"];
            pre.LocationManaged = collection["LocationManaged"] == "1" ? 1 : 0;
            pre.LocationStatus = LocationStatus;
            pre.RefListID = "," + collection["LocationType[]"] + ",";
            pre.LocationStatusDate = _db.ConvertDate(collection["LocationStatusDate"], "dd/MM/yyyy");
            pre.PremiseAddr1 = collection["PremiseAddr1"];
            pre.PremiseAddr2 = collection["PremiseAddr2"];
            pre.PremiseAddr3 = collection["PremiseAddr3"];
            pre.LocationDescription = collection["LocationDescription"];
            pre.PremisePostCode = collection["PostCode"];
            pre.CityTown = collection["CityTown"];
            pre.PremisePhone = PremisePhone;
            pre.County = collection["County"];
            pre.PremisFax = collection["PremisFax"];
            pre.CountryID = CountryID;
            pre.PremisMinicomn = collection["PremisMinicomn"];
            pre.PremiseIsNew = collection["PremiseIsNew"] == "1" ? 1 : 0;
            pre.PremiseShopFlagDate = _db.ConvertDate(collection["PremiseShopFlagDate"], "dd/MM/yyyy");
            pre.PremiseSpecialistShop = collection["PremiseSpecialistShop"] == "1" ? 1 : 0;
            pre.LocationOrganisation = LocationOrganisation;
            pre.PremiseIsActive = 1;

            var detail = new PremiseDetail();

            detail.RefListID = "," + collection["RefListID[]"] + ",";
            detail.MediaContactCheck = collection["MediaContactCheck"] == "1" ? 1 : 0;
            detail.CateringFacilities = collection["CateringFacilities"] == "1" ? 1 : 0;
            detail.MediaContact = MediaContact;
            detail.CateringContact = CateringContact;
            detail.CateringType = CateringType;
            detail.ClientITFacilities = collection["ClientITFacilities"] == "1" ? 1 : 0;
            detail.LocalDemographicNote = collection["LocalDemographicNote"];
            detail.MediaContactCheck = collection["MediaContactCheck"] == "1" ? 1 : 0;
            detail.ClientITFacilitiesDetail = collection["ClientITFacilitiesDetail"];
            detail.RoomAvailability = collection["RoomAvailability"] == "1" ? 1 : 0;
            detail.VolunteeringOpportunuties = collection["VolunteeringOpportunuties"] == "1" ? 1 : 0;
            detail.PremiseOutreachLocationListID = "," + collection["PremiseOutreachLocationListID[]"] + ",";
            detail.PremiseLocalHotelListID = "," + collection["PremiseLocalHotelListID[]"] + ",";
            detail.TravelDetail = collection["TravelDetail"];
            detail.VisitorParkingOnsite = collection["VisitorParkingOnsite"] == "1" ? 1 : 0;
            detail.TravelNearestBus = collection["TravelNearestBus"];
            detail.VisitorParkingSpace = VisitorParkingSpace;
            detail.TravelNearestRail = collection["TravelNearestRail"];
            detail.VisitorParkingAlternative = collection["VisitorParkingAlternative"];
            detail.TravelNearestAirport = collection["TravelNearestAirport"];
            detail.HostVisits = collection["HostVisits"] == "1" ? 1 : 0;
            detail.HostingContact = HostingContact;
            detail.TravelNearestAirport = collection["TravelNearestAirport"];

            var cost = new PermiseDetailForCost();
            cost.RoomOnlyRate = collection["RoomOnlyRate"];
            cost.NegotiatedRoomonlyRate = collection["NegotiatedRoomonlyRate"];
            cost.BBRate = collection["BBRate"];
            cost.BBNegotiatedRate = collection["BBNegotiatedRate"];
            cost.DBBRate = collection["DBBRate"];
            cost.DBBNegotiatedRate = collection["DBBNegotiatedRate"];
            cost.DDRate = collection["DDRate"];
            cost.DDNegotiatedRate = collection["DDNegotiatedRate"];
            cost.pre24hrRate = collection["pre24hrRate"];
            cost.pre24hrNeotiatedRate = collection["pre24hrNeotiatedRate"];
            cost.TeaAndCoffee = collection["TeaAndCoffee"];
            cost.LastNegotiatedDate = _db.ConvertDate(collection["LastNegotiatedDate"], "dd/MM/yyyy");
            cost.Lunch = collection["Lunch"] == "1" ? 1 : 0;
            cost.RenegotiateOn = _db.ConvertDate(collection["RenegotiateOn"], "dd/MM/yyyy");
            cost.NoOfMeetingRooms = NoOfMeetingRooms;
            cost.PreferredStatus = PreferredStatus;
            cost.MeetingRoomRatePerDay = collection["MeetingRoomRatePerDay"];
            cost.Comments = collection["Comments"];
            cost.Codings = Codings;

            var model = new PremiseOpenSchedule();
            model.StartMonday = collection["StartMonday"];
            model.EndMonday = collection["EndMonday"];
            model.StartTuesday = collection["StartTuesday"];
            model.EndTuesday = collection["EndTuesday"];
            model.StartWednesday = collection["StartWednesday"];
            model.EndWednesday = collection["EndWednesday"];
            model.StartThursday = collection["StartThursday"];
            model.EndThursday = collection["EndThursday"];
            model.StartFriday = collection["StartFriday"];
            model.EndFriday = collection["EndFriday"];
            model.StartSaturday = collection["StartSaturday"];
            model.EndSaturday = collection["EndSaturday"];
            model.StartSunday = collection["StartSunday"];
            model.EndSunday = collection["EndSunday"];

            var isSaved=_db.CreatePremise(pre, detail, cost, model);
            if (isSaved == true)
            {
                ViewBag.Alert = "true";
                ViewBag.Message = "Action success!";
                ViewBag.URL = "/Premise/Amend/" + pre.PremiseID;
            }
            else
            {
                ViewBag.Alert = "false";
                ViewBag.Message = "";
                ViewBag.URL = "";
            }
            return PartialView("../Shared/Redirect");
        }
 partial void DeletePremiseDetail(PremiseDetail instance);
 partial void UpdatePremiseDetail(PremiseDetail instance);
 partial void InsertPremiseDetail(PremiseDetail instance);
		private void detach_PremiseDetails2(PremiseDetail entity)
		{
			this.SendPropertyChanging();
			entity.Contact2 = null;
		}
		private void attach_PremiseDetails1(PremiseDetail entity)
		{
			this.SendPropertyChanging();
			entity.Contact1 = this;
		}