当前位置: 首页>>代码示例>>C#>>正文


C# PortugalVillasContext.Entry方法代码示例

本文整理汇总了C#中BootstrapVillas.Models.PortugalVillasContext.Entry方法的典型用法代码示例。如果您正苦于以下问题:C# PortugalVillasContext.Entry方法的具体用法?C# PortugalVillasContext.Entry怎么用?C# PortugalVillasContext.Entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BootstrapVillas.Models.PortugalVillasContext的用法示例。


在下文中一共展示了PortugalVillasContext.Entry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestBookingSteps

        public ActionResult TestBookingSteps(Customer cus, CustomerBankDetail bank, List<Booking> bookings = null, List<BookingExtraSelection> bookingExtraSelections = null, List<BookingParticipant> bookingParticipants = null)
        {
            Session["prc_customer"] = new Customer();


            using (var db = new PortugalVillasContext())
            {
                var eventService = new EventController();
                var bookingRepo = new FinalBookingDetailGatheringController();
                //CUSTOMER
                //does customer have ID? if not create new Customer
                if (cus.CustomerID.Equals(0))
                {
                    bookingRepo.CreateCustomer(cus, db);
                }
                else
                {
                    //update customer with new details
                    /*cus.BookingExtraSelections = null;
                    cus.Bookings = null;
                    cus.CreationDate = cus.CreationDate;

                    db.Customers.Attach(cus);
                    db.Entry(cus).State = EntityState.Modified;

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (OptimisticConcurrencyException)
                    {
                       
                    }
                    */
                }

                //BANK DETAIL
                if (bank.CustomerBankDetailID.Equals(0))
                {
                    bookingRepo.CreateCustomerBankDetail(bank, cus, db);
                }
                else
                {
                    //update customer with new details
                    db.CustomerBankDetails.Attach(bank);
                    db.Entry(bank).State = EntityState.Modified;
                    db.SaveChanges();
                }




                //////////////////
                //BOOKING
                //create a parent booking thingy and link it
                BookingParentContainer parentContainer = new BookingParentContainer();
                parentContainer.CustomerID = cus.CustomerID;

                parentContainer = bookingRepo.CreateBookingParentContainer(parentContainer, db);


                foreach (var booking in bookings)
                {   //link to parent booking
                    booking.BookingParentContainerID = parentContainer.BookingParentContainerID;
                    //fill em out and push them to the DB


                  /*  bookingRepo.CreateBooking(booking, cus, db);*/

                    
                    var participantsThisRound =
                        bookingParticipants.Where(x => x.StepNo.Equals(bookingParticipants.Min(y => y.StepNo))).ToList();
                    //create the participants

                    foreach (var bookingParticipant in participantsThisRound)
                    {
                        if (bookingParticipant.BookingParticipantFirstName != "" && bookingParticipant.BookingParticipantFirstName != null 
                            && bookingParticipant.BookingParticipantLastName != "" &&
                             bookingParticipant.BookingParticipantLastName != null)
                        {
                            bookingRepo.CreateBookingParticipant(participantsThisRound, booking, db);
                        }        
                    }
                    


                    foreach (var bookingParticipant in participantsThisRound)
                    {
                        bookingParticipants.Remove(bookingParticipant);               
                    }
         

                    


                    //now check which booking form to send depending on location
                    string EventTypeID;
                    if (cus.Country.ToUpper() == "GB")
                    {
                        EventTypeID = "17";
//.........这里部分代码省略.........
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:101,代码来源:TestController.cs

示例2: Edit

        public ActionResult Edit(PropertyOwner propertyowner)
        {
            propertyowner.WhenCreated = DateTime.Now;
            propertyowner.WhenUpdated =
                db.PropertyOwners.Where(x => x.PropertyOwnerID == propertyowner.PropertyOwnerID).First().WhenUpdated;


            if (ModelState.IsValid)
            {
                using (var _db = new PortugalVillasContext())
                {
                    _db.PropertyOwners.Attach(propertyowner);
                    _db.Entry(propertyowner).State = EntityState.Modified;
                    _db.SaveChanges();
                    return RedirectToAction("Edit", new { id = propertyowner.PropertyOwnerID });    
                }
                
                
            }
            return View(propertyowner);
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:21,代码来源:PropertyOwnerController.cs

示例3: Edit

        public ActionResult Edit(BookingParticipant bookingparticipant)
        {
            var oldPart = db.BookingParticipants.Where(x => x.BookingParticipantID == bookingparticipant.BookingParticipantID).FirstOrDefault();

            bookingparticipant.BookingParticipantWhenCreated = oldPart.BookingParticipantWhenCreated;
            if (ModelState.IsValid)
            {
                using (var _db = new PortugalVillasContext())
                {
                    _db.BookingParticipants.Attach(bookingparticipant);
                    _db.Entry(bookingparticipant).State = EntityState.Modified;
                    _db.SaveChanges();
                    return RedirectToAction("Index", "BookingParticipant", new { bookingID = bookingparticipant.BookingID });
                }
            }
            ViewBag.BookingID = new SelectList(db.Bookings, "BookingID", "BookingPRCReference", bookingparticipant.BookingID);
            return View(bookingparticipant);
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:18,代码来源:BookingParticipantController.cs

示例4: Edit

        public ActionResult Edit(PropertyTown propertytown)
        {
            if (ModelState.IsValid)
            {

                using (var _db = new PortugalVillasContext())
                {
                    _db.PropertyTowns.Attach(propertytown);
                    _db.Entry(propertytown).State = EntityState.Modified;
                    _db.SaveChanges();
                    ViewBag.PropertyRegionID = new SelectList(db.PropertyRegions, "PropertyRegionID", "RegionName",
                        propertytown.PropertyRegionID);
                    return RedirectToAction("Edit", new {id = propertytown.PropertyTownID});
                }
            }
            ViewBag.PropertyRegionID = new SelectList(db.PropertyRegions, "PropertyRegionID", "RegionName", propertytown.PropertyRegionID);
            return View(propertytown);
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:18,代码来源:PropertyTownController.cs

示例5: CreateBookingExtraSelection

        public BookingExtraSelection CreateBookingExtraSelection(BookingExtraSelection bookingExtraSelection, BookingExtra extra, Customer theCustomer, PortugalVillasContext db)
        {
            bookingExtraSelection.BESCurrencyConversionSymbol = theCustomer.PreferredCurrencySymbol;
            bookingExtraSelection.BESPreferredCurrency = theCustomer.PreferredCurrency;

            var cc = new CurrencyConverterController();


            long? currentBookingTypeID = bookingExtraSelection.GetBookingExtraTypeIDFromBookingExtraSelection();
            bookingExtraSelection.CustomerID = theCustomer.CustomerID;

            //the price already needs to be assigned
            bookingExtraSelection.BESPrice = BookingExtraSelection.GetBookingExtraPrice(bookingExtraSelection, db);
            bookingExtraSelection.BESExtraServicesPrice = BookingExtraSelection.CalculateBookingExtraAdditionalCostsAndAssignToThisBooking(bookingExtraSelection, db);

            bookingExtraSelection.BESTotalServicesPrice = BookingExtraSelection.GetBookingExtraTotalServicesPrice(bookingExtraSelection, db);


            bookingExtraSelection.WhenCreated = DateTime.Now;

            //calc number of guests
            if (bookingExtraSelection.NumberOfGuests == null || bookingExtraSelection.NumberOfGuests == 0)
            {
                bookingExtraSelection.CalculateNoOfGuests();
            }

            //if not UK need to do currency conversion
            if (theCustomer.Country.ToLower() != "united kingdom" && ConfigurationManager.AppSettings["defaultCurrency"] == "GBP")
            {
                var baseCurrency = "GBP";
                var newCurrency = "EUR";

                var exchangeRateFromDB =
                    db.CurrencyExchanges.First(x => x.CurrencyExchangeName == "GBP-EUR");

                try
                {
                    bookingExtraSelection.BESPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESPrice);
                    bookingExtraSelection.BESCurrencyConversionPrice = bookingExtraSelection.BESPrice;
                    bookingExtraSelection.BESExtraServicesPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESExtraServicesPrice);
                    bookingExtraSelection.BESTotalServicesPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESTotalServicesPrice);

                

                    //set exchange rate
                    bookingExtraSelection.BESCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol;
                    bookingExtraSelection.BESCurrencyExchangeRate = exchangeRateFromDB.CurrencyExchangeRate;
                    bookingExtraSelection.BESPreferredCurrency = "EUR";
                }
                catch (Exception)
                {

                    throw;
                }

            }

            else if (ConfigurationManager.AppSettings["defaultCurrency"] == "USD")
            {
                var baseCurrency = "GBP";
                var newCurrency = "USD";

                var exchangeRateFromDB =
                    db.CurrencyExchanges.First(x => x.CurrencyExchangeName == "GBP-USD");

                try
                {
                    bookingExtraSelection.BESPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESPrice);
                    bookingExtraSelection.BESCurrencyConversionPrice = bookingExtraSelection.BESPrice;
                    bookingExtraSelection.BESExtraServicesPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESExtraServicesPrice);
                    bookingExtraSelection.BESTotalServicesPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESTotalServicesPrice);


                    //set exchange rate
                    bookingExtraSelection.BESCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol;
                    bookingExtraSelection.BESCurrencyExchangeRate = exchangeRateFromDB.CurrencyExchangeRate;
                    bookingExtraSelection.BESPreferredCurrency = "USD";
                }
                catch (Exception)
                {

                    throw;
                }
            }

            //generate reference
            var refGenService = new ReferenceGenerationService();
            bookingExtraSelection.BookingExtraPRCReference = refGenService.GenerateBESReference(bookingExtraSelection, extra);


            if (ModelState.IsValid)
            {
                db.BookingExtraSelections.Add(bookingExtraSelection);
                if (db.SaveChanges() > 0)
                {
                    //generate reference with ID
                    bookingExtraSelection.BookingExtraPRCReference = refGenService.GenerateBESReference(bookingExtraSelection, extra);

                    db.Entry(bookingExtraSelection).State = EntityState.Modified;
                    db.SaveChanges();
//.........这里部分代码省略.........
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:101,代码来源:FinalBookingDetailGatheringController.cs

示例6: Edit

        public ActionResult Edit(Customer customer)
        {


            var oldCust = db.Customers.Where(x => x.CustomerID == customer.CustomerID).First();
            customer.CreationDate = customer.CreationDate;


            if (ModelState.IsValid)
            {
                using (var _db = new PortugalVillasContext())
                {
                    _db.Customers.Attach(customer);
                    _db.Entry(customer).State = EntityState.Modified;
                    _db.SaveChanges();
                    Session["currentCustomer"] = customer;
                    return RedirectToAction("Edit", customer);
                }

            }
            return View(customer);
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:22,代码来源:CustomerController.cs

示例7: EditCustomer

 public ActionResult EditCustomer(Customer customer)
 {
     PortugalVillasContext db = new PortugalVillasContext();
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(customer);
 }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:11,代码来源:FinalBookingDetailGatheringController.cs

示例8: CreateBooking


//.........这里部分代码省略.........
                        booking.TowelsPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.TowelsPrice);
                        booking.MidVactionCleaningPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.MidVactionCleaningPrice);
                        booking.SwimmingPoolHeatingPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.SwimmingPoolHeatingPrice);
                        booking.ExtraLininSetPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.ExtraLininSetPrice);
                        booking.BreakageDeposit = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.BreakageDeposit);
                        booking.CleaningPostVisitPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.CleaningPostVisitPrice);
                        booking.HeatingPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.HeatingPrice);


                        booking.HeatingUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.HeatingUnitPrice);
                        booking.CleaningPostVisitUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.CleaningPostVisitUnitPrice);
                        booking.ExtraLininSetUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.ExtraLininSetUnitPrice);
                        booking.MidVactionCleaningUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.MidVactionCleaningUnitPrice);
                        booking.SwimmingPoolHeatingUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.SwimmingPoolHeatingUnitPrice);
                        booking.TowelsUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.TowelsUnitPrice);
                        booking.FirewoodUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                            (decimal)booking.FirewoodUnitPrice);

                    }
                    catch (Exception)
                    {

                        throw;
                    }
                }

            }
            catch (Exception ex)
            {
                /*Response.Redirect("http://" + Request.Url.Authority + "/Error/PropertyErrorSelection");*/
                //return RedirectToAction("PropertyErrorSelection", "Error", new { propID = CartBooking.PropertyID });                    
            }


            //CURRENCY MUST BE CONVERTED BEFORE THESE METHODS ARE CALLED

            //call meths to set dates
            booking.SetInitalDepositDate();
            booking.SetInitialDepositAmount();

            booking.SetRentalBalanceDueDate(); //1 month before
            booking.CalculateFinalRentalPaymentAmount(); //extrasSummedPrice + price - deposit


            booking.SetBreakageDepositRemittanceDate();
            booking.SetBreakageDepositRemittanceAmount();//1 month after trip end?
            //booking.SetFinalRentalPayment(); //price - deposit

            booking.SetHomeownerAndPRCComissionAmount(db);

            booking.CreationDate = DateTime.Now;


            booking.Cancelled = false;
            booking.Confirmed = false; //if they pay by paypal later, we can update;




            var refGenService = new ReferenceGenerationService();
            booking.BookingPRCReference = refGenService.GenerateBookingReference(booking, property);


            //if (ModelState.IsValid)
            //{

            db.Bookings.Add(booking);

            if (db.SaveChanges() > 0)
            {

                if (booking.BookingID > 0)
                {
                    booking.BookingPRCReference = refGenService.GenerateBookingReference(booking, property);

                    db.Entry(booking).State = EntityState.Modified;
                    db.SaveChanges();

                }





            }
            return booking;
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:101,代码来源:FinalBookingDetailGatheringController.cs

示例9: ManageCustomerBankDetail

        public ActionResult ManageCustomerBankDetail(CustomerBankDetail aCustomerBankDetail)
        {
            try
            {
                PortugalVillasContext _dbContext = new PortugalVillasContext();
                Customer customer = GetCustomerForLoggedInCustomerAndStoreInSession(HttpContext.User.Identity.Name);
                aCustomerBankDetail.CustomerID = customer.CustomerID;
                _dbContext.Entry(aCustomerBankDetail).State = EntityState.Modified;

                var objContext = ((IObjectContextAdapter)_dbContext).ObjectContext;

                var refreshableObjects = (from entry in objContext.ObjectStateManager.GetObjectStateEntries(
                    EntityState.Added
                    | EntityState.Deleted
                    | EntityState.Modified
                    | EntityState.Unchanged)
                                          where entry.EntityKey != null
                                          select entry.Entity);

                objContext.Refresh(RefreshMode.ClientWins, refreshableObjects);


                if (ModelState.IsValid)
                {

                    if (objContext.SaveChanges() > 0) ;
                    {
                        return View("CustomerUpdateSuccess");

                    }

                }


            }
            catch (Exception exception)
            {

                throw exception;
            }


            return View("CustomerUpdateFailed");
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:44,代码来源:AccountController.cs

示例10: Edit

        public ActionResult Edit(BookingExtra bookingextra)
        {
            var oldExtra = db.BookingExtras.Where(x => x.BookingExtraID == bookingextra.BookingExtraID).First();
            bookingextra.WhenCreated = oldExtra.WhenCreated;
            bookingextra.WhenModified = oldExtra.WhenModified;

            if (ModelState.IsValid)
            {
                using (var _db = new PortugalVillasContext())
                {
                    _db.BookingExtras.Attach(bookingextra);
                    _db.Entry(bookingextra).State = EntityState.Modified;
                    _db.SaveChanges();
                    ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID",
                        "ExtraTypeName", bookingextra.BookingExtraTypeID);
                    return RedirectToAction("SingleBookingExtraIndex", "BookingExtra",
                        new {bookingextraID = bookingextra.BookingExtraID});
                }
            }
            ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
            return View(bookingextra);
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:22,代码来源:BookingExtraController.cs

示例11: ManageCustomer

        //  [Authorize(Roles = "Administrator, User")]
        public ActionResult ManageCustomer(Customer customer)
        {


            Customer previousCustomer = (Customer)Session["prc_previouscustomer"];
            customer.CustomerID = previousCustomer.CustomerID;


            if ((!CheckIfCustomerEmailAlreadyExists(customer.EmailAddress) &&
                !CheckIfUserExistsInSimpleMemberProvider(customer.EmailAddress)) || (previousCustomer.EmailAddress.ToLower().Trim() == customer.EmailAddress.ToLower().Trim()))
            {

                PortugalVillasContext _dbContext = new PortugalVillasContext();
                UsersContext _usersContext = new UsersContext();

                //get the old customer detailf from the session



                //update simplemembership provider too
                var user =
                    _usersContext.UserProfiles.Where(
                        x => x.UserName.ToLower().Trim() == previousCustomer.EmailAddress.ToLower().Trim())
                        .FirstOrDefault();

                user.UserName = customer.EmailAddress;

                //update customer and user
                try
                {
                    if (ModelState.IsValid)
                    {
                        _dbContext.Entry(customer).State = EntityState.Modified;
                        var objContext = ((IObjectContextAdapter)_dbContext).ObjectContext;

                        var refreshableObjects = (from entry in objContext.ObjectStateManager.GetObjectStateEntries(
                            EntityState.Added
                            | EntityState.Deleted
                            | EntityState.Modified
                            | EntityState.Unchanged)
                                                  where entry.EntityKey != null
                                                  select entry.Entity);

                        objContext.Refresh(RefreshMode.ClientWins, refreshableObjects);

                        //if it works, do the update for the userContext, else, don't as it failed
                        if (objContext.SaveChanges() > 0)
                        {
                            _usersContext.Entry(user).State = EntityState.Modified;
                            _usersContext.SaveChanges();

                            WebSecurity.Logout();

                            Session["prc_customer"] = customer;
                            //update the customer
                            return View("CustomerUpdateSuccess");
                        }

                    }
                }

                catch
            (DbUpdateConcurrencyException ex)
                {
                    var objContext = ((IObjectContextAdapter)_dbContext).ObjectContext;
                    var entry = ex.Entries.Single();

                    objContext.Refresh(RefreshMode.ClientWins, entry.Entity);
                    _dbContext.SaveChanges();


                }

            }


            //update the customer on result
            ViewBag.Title = "Manage Portugal Holiday Rentals Customer";
            return View("CustomerUpdateFailed");


        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:83,代码来源:AccountController.cs

示例12: Edit

        public ActionResult Edit(Booking booking)
        {
            var oldbook = db.Bookings.Where(x => x.BookingID == booking.BookingID).FirstOrDefault();

            booking.CreationDate = oldbook.CreationDate;
            booking.LastUpdated = oldbook.LastUpdated;

            if (ModelState.IsValid)
            {
                using (var _db = new PortugalVillasContext())
                {
                    _db.Bookings.Attach(booking);
                    _db.Entry(booking).State = EntityState.Modified;
                    _db.SaveChanges();
                    ViewBag.BookingParentContainerID = new SelectList(db.BookingParentContainers,
                        "BookingParentContainerID", "OverallBookingReference", booking.BookingParentContainerID);
                    ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Title", booking.CustomerID);
                    ViewBag.PropertyID = new SelectList(db.Properties, "PropertyID", "LegacyReference",
                        booking.PropertyID);

                    return View("SingleBookingIndex", db.Bookings.Include(x => x.Customer).FirstOrDefault(x => x.BookingID == booking.BookingID));
                }
            }

            ViewBag.BookingParentContainerID = new SelectList(db.BookingParentContainers, "BookingParentContainerID", "OverallBookingReference", booking.BookingParentContainerID);
            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Title", booking.CustomerID);
            ViewBag.PropertyID = new SelectList(db.Properties, "PropertyID", "LegacyReference", booking.PropertyID);
            return View("SingleBookingIndex", db.Bookings.Include(x => x.Customer).FirstOrDefault(x => x.BookingID == booking.BookingID));
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:29,代码来源:BookingController.cs

示例13: Edit

 public ActionResult Edit(PropertyOwnerRepresentative propertyownerrepresentative)
 {
     if (ModelState.IsValid)
     {
         using (var _db = new PortugalVillasContext())
         {
             _db.PropertyOwnerRepresentatives.Attach(propertyownerrepresentative);
             _db.Entry(propertyownerrepresentative).State = EntityState.Modified;
             _db.SaveChanges();
             return RedirectToAction("Edit", new {id = propertyownerrepresentative.PropertyOwnerRepresentativeID});
         }
     }
     return View(propertyownerrepresentative);
 }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:14,代码来源:PropertyOwnerRepresentativeController.cs

示例14: GetBookingDetails

        public ActionResult GetBookingDetails(Customer cus, CustomerBankDetail bank, List<Booking> bookings = null, List<BookingExtraSelection> bookingExtraSelections = null, List<BookingParticipant> bookingParticipants = null)
        {
            //set customer preferred currency symbol and currency

            using (var db = new PortugalVillasContext())
            {

                var account = new AccountController();
                var eventService = new EventController();
                var bookingRepo = new FinalBookingDetailGatheringController();
                //CUSTOMER
                //does customer have ID? if not create new Customer
                if (cus.CustomerID.Equals(0))
                {
                    var returnedCus = bookingRepo.CreateCustomer(cus, db);
                    cus = returnedCus;
                    Session["prc_customer"] = returnedCus;
                }
                else
                {
                    //update customer with new details
                    cus.BookingExtraSelections = null;
                    cus.Bookings = null;

                    //Do the UPDATE
                    if (ModelState.IsValid)
                    {
                        db.Entry(cus).State = EntityState.Modified;
                        var objContextCus = ((IObjectContextAdapter)db).ObjectContext;

                        var refreshableObjectsCus =
                            (from entry in objContextCus.ObjectStateManager.GetObjectStateEntries(
                                EntityState.Added
                                | EntityState.Deleted
                                | EntityState.Modified
                                | EntityState.Unchanged)
                             where entry.EntityKey != null
                             select entry.Entity);

                        objContextCus.Refresh(RefreshMode.ClientWins, refreshableObjectsCus);

                        //if it works, do the update for the userContext, else, don't as it failed
                        if (objContextCus.SaveChanges() > 0)
                        {
                            /*_usersContext.Entry(user).State = EntityState.Modified;
                            _usersContext.SaveChanges();*/
                        }



                    }
                }

                //BANK DETAIL
                if (bank.CustomerBankDetailID.Equals(0))
                {
                    var returnedBank = bookingRepo.CreateCustomerBankDetail(bank, cus, db);
                    Session["prc_customerBankingDetail"] = returnedBank;
                }
                else
                {
                    bank.CustomerID = cus.CustomerID;
                    db.Entry(bank).State = EntityState.Modified;

                    var objContext = ((IObjectContextAdapter)db).ObjectContext;

                    var refreshableObjects = (from entry in objContext.ObjectStateManager.GetObjectStateEntries(
                        EntityState.Added
                        | EntityState.Deleted
                        | EntityState.Modified
                        | EntityState.Unchanged)
                                              where entry.EntityKey != null
                                              select entry.Entity);

                    objContext.Refresh(RefreshMode.ClientWins, refreshableObjects);


                    if (ModelState.IsValid)
                    {

                        if (objContext.SaveChanges() > 0) ;
                        {
                            //great it worked
                        }
                    }

                }


                //parent
                BookingParentContainer parentContainer = new BookingParentContainer();
                parentContainer.CustomerID = cus.CustomerID;


                parentContainer = bookingRepo.CreateBookingParentContainer(parentContainer, db);
                //need to add booking reference then propagate to all others below


                //////////////////
                //BOOKING
//.........这里部分代码省略.........
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:101,代码来源:DetailVerifyController.cs

示例15: Edit

        public ActionResult Edit(PropertyRegion propertyregion)
        {
            if (ModelState.IsValid)
            {
                using (var _db = new PortugalVillasContext())
                {
                    _db.PropertyRegions.Attach(propertyregion);
                    _db.Entry(propertyregion).State = EntityState.Modified;
                    _db.SaveChanges();
                    return RedirectToAction("Edit", new { id = propertyregion.PropertyRegionID });    
                }

                
            }
            return View(propertyregion);
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:16,代码来源:PropertyRegionController.cs


注:本文中的BootstrapVillas.Models.PortugalVillasContext.Entry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。