//Original method - takes long, returns list
        protected List <EntityTypeDetailField> GetAllEntityDetailFieldsOfEntityType(long anEntityTypeID)
        {
            //test for Entity Type
            //add necessary fields to list
            //return lists
            PortugalVillasContext _db = new PortugalVillasContext();

            var theEntityTypeDetailFields = _db.EntityTypeDetailFields
                                            .Where(x => x.EntityTypeID == anEntityTypeID)
                                            .ToList();

            return(theEntityTypeDetailFields);
        }
 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));
 }
示例#3
0
        /// <summary>
        /// Edit and existing customer
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult EditCustomer(decimal id = 0)
        {
            PortugalVillasContext db = new PortugalVillasContext();

            Customer customer = db.Customers.Find(id);

            if (customer == null)
            {
                return(HttpNotFound());
            }

            db.Dispose();
            return(RedirectToAction("DetailGatheringEventChain"));
        }
示例#4
0
        public void TestDocumentReadAndInsert()
        {
            var files = Directory.GetFileSystemEntries(Server.MapPath("~/Documents"), "*.pdf", SearchOption.AllDirectories);

            var bDoc = new Document();

            bDoc.DocumentBLOB = System.IO.File.ReadAllBytes(files[0]);

            using (var db = new PortugalVillasContext())
            {
                db.Documents.Add(bDoc);
                db.SaveChanges();
            }
        }
 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));
 }
        //Overload 1 - takes EntityType
        protected List <long> GetAllEntityDetailFieldsOfEntityType(EntityType anEntityType)
        {
            //test for Entity Type
            //add necessary fields to list
            //return lists
            PortugalVillasContext _db = new PortugalVillasContext();

            var theEntityTypeDetailFields = _db.EntityTypeDetailFields
                                            .Where(x => x.EntityTypeID == anEntityType.EntityTypeID)
                                            .ToList();

            List <long> theDetailFieldIDsToReturn = new List <long>();

            return(theDetailFieldIDsToReturn);
        }
        public ActionResult ManageCustomerPassword()
        {
            PortugalVillasContext _dbContext    = new PortugalVillasContext();
            UsersContext          _usersContext = new UsersContext();

            //get the customer from the db according to who's logged in

            //Show the customer to the suer

            //update the customer

            //update the SIMPLEMEMBERSHIPPROVDER CORRESPONDING RECORD!! (if they change the email!!)

            //update the
            return(View());
        }
        public ActionResult ManageCustomer()
        {
            PortugalVillasContext _dbContext = new PortugalVillasContext();


            //get the customer from the db according to who's logged in
            string user = System.Web.HttpContext.Current.User.Identity.Name;
            //Show the customer to the suer
            Customer theCustomer = Customer.GetCustomerByEmailAddress(user);

            //update the customer
            Session["prc_previouscustomer"] = theCustomer;

            ViewBag.Title = "Manage Portugal Holiday Rentals Customer";
            return(View(theCustomer));
        }
        /// <summary>
        /// Populates the daterange
        ///
        ///For this price range -
        ///make the start and end dates proper dates (append year from 'theBookingDate'
        ///add start date to list. keep adding dates until enddate (and also add that)
        /// </summary>
        /// <returns></returns>
        ///
        private bool PopulateTheRangeOfDatesBetweenStartAndEndDates(PropertyPricingSeasonalInstance aPropertyPricing)
        {
            try
            {
                //make sure list is blank
                theRangeOfDatesBetweenStartAndEndDates = null;
                theRangeOfDatesBetweenStartAndEndDates = new List <DateTime>();

                CurrentPriceForRange = null;
                CurrentPriceForRange = aPropertyPricing.Price;


                if (aPropertyPricing.PropertyPricingSeason == null)
                {
                    using (var db = new PortugalVillasContext())

                    {
                        aPropertyPricing.PropertyPricingSeason =
                            db.PropertyPricingSeasons.Find(aPropertyPricing.PropertyPricingSeasonID);
                    }
                }


                DateTime startDate = (DateTime)aPropertyPricing.PropertyPricingSeason.SeasonStartDate;
                DateTime endDate   = (DateTime)aPropertyPricing.PropertyPricingSeason.SeasonEndDate;


                int currentDateIterator = (endDate - startDate).Days;
                currentDateIterator -= 1;
                DateTime currentDate = startDate;
                theRangeOfDatesBetweenStartAndEndDates.Add(currentDate);

                //add a day to startdate for the number of days we need, then add this
                for (int i = 0; i <= currentDateIterator; i++)
                {
                    currentDate = currentDate.AddDays(1);
                    theRangeOfDatesBetweenStartAndEndDates.Add(currentDate);
                }


                return(true);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 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));
 }
示例#11
0
        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));
        }
示例#12
0
        public ActionResult BookCarRental()
        {
            //NB - need a method to get all
            //pull back from db the correct extra and pass to viewbag
            List <BookingExtra> CarBookingExtras = BookingExtra.GetBookingExtrasOfType();

            foreach (var cbe in CarBookingExtras)
            {
                cbe.GetAllBookingExtraAttributes();
            }

            //get all the images for all the extras
            List <ExtrasImage> allTheExtraImages = new List <ExtrasImage>();

            ViewBag.CarBookingExtras = CarBookingExtras;

            //list of airports for  transfers

            //drop down lists
            using (var _db = new PortugalVillasContext())
            {
                var listOfAllTypes = _db.BookingExtraTypes.ToSafeReadOnlyCollection();
                //create list and put in viewbag
                List <SelectListItem> selectListOfAllTypes = new List <SelectListItem>();
                selectListOfAllTypes.Add(new SelectListItem {
                    Text = "Show All", Value = "0"
                });

                foreach (var type in listOfAllTypes)
                {
                    selectListOfAllTypes.Add(new SelectListItem {
                        Text = type.ExtraTypeName, Value = type.BookingExtraTypeID.ToString()
                    });
                }
                //add a default


                ViewBag.ExtraTypes = selectListOfAllTypes;
            }

            ViewBag.Keywords = "Portugal Villas, portugal rental cottages, cheap holidays to portugal, silver coast villas,cheap portugal holidays,villa hotel rental portugal";
            ViewBag.Title    = "A quality selection of cars that includes the Hyundai I20,Mitsubishi Colt, Mitsubishi Colt Diesel, Mitsubishi Lancer, Mitsubishi Grandis, you can also book direct airport transfers here to drop you from the airport directly to your villas and add package and sightseeing tours for you and the family, to well loved destinations like Alcobaça, Batalha and Fatima, the Sintra Palace or Obidos and Nazare. See the EXPO 98 & Ocenarium or stay in Salir do Porto, sunny Formigal or the beautiful A-da-Gorda. With cheap seasonal holiday rentals in Sao Martinho do Porto, Barrantes, Capeleira and Sancheira Pequena you can get quality Portugese accommodation the entire year round.";
            return(View());
        }
示例#13
0
        //
        // POST: /FinalBookingDetailGathering/Create


        public bool CreateCustomerAsPartOfSignUp(Customer customer)
        {
            PortugalVillasContext db = new PortugalVillasContext();

            if (ModelState.IsValid)
            {
                //CHECK IF THERE'S ALREADY A CUSTOMER WITH THIS EMAIL ADDRESS FIRST!!!

                //end check

                //CHECK we ain't got anything for this customer in the Sessions already

                //end check


                //if not, add customer

                //set up fields

                customer.CreationDate = DateTime.Now;
                if (customer.Country.ToLower() == "united kingdom")
                {
                    customer.PreferredCurrency       = "GBP";
                    customer.PreferredCurrencySymbol = "£";
                }
                else
                {
                    customer.PreferredCurrency       = "EUR";
                    customer.PreferredCurrencySymbol = "€";
                }
                //end

                db.Customers.Add(customer);

                if (db.SaveChanges() > 0)
                {
                    //customer now has an ID if the save has worked
                    System.Web.HttpContext.Current.Session["prc_customer"] = customer;

                    return(true);
                }
            }
            return(false);
        }
示例#14
0
        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));
        }
        public Customer GetCustomerForLoggedInCustomerAndStoreInSession(string email)
        {
            Customer customer = null;

            try
            {
                PortugalVillasContext _db = new PortugalVillasContext();

                customer =
                    _db.Customers.Where(x => x.EmailAddress.Trim().ToLower() == email.Trim().ToLower()).FirstOrDefault();

                Session["prc_customer"] = customer;
            }
            catch (Exception exception)
            {
                throw exception;
            }

            return((Customer)customer);
        }
        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));
        }
        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"));
        }
        public ActionResult Edit(BookingExtraParticipant bookingextraparticipant)
        {
            var old =
                db.BookingExtraParticipants.Where(
                    c => c.BookingExtraSelectionID == bookingextraparticipant.BookingExtraSelectionID).FirstOrDefault();

            bookingextraparticipant.BookingExtraParticipantWhenCreated = old.BookingExtraParticipantWhenCreated;

            if (ModelState.IsValid)
            {
                using (var _db = new PortugalVillasContext())
                {
                    _db.BookingExtraParticipants.Attach(bookingextraparticipant);
                    _db.Entry(bookingextraparticipant).State = EntityState.Modified;
                    _db.SaveChanges();
                    return(RedirectToAction("Index",
                                            new { BookingExtraSelectionId = bookingextraparticipant.BookingExtraSelectionID }));
                }
            }
            ViewBag.ID = (long)Session["recentBES"];
            return(View(bookingextraparticipant));
        }
        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));
        }
示例#20
0
        public void TestEventCommandAndLogging()
        {
            var db = new PortugalVillasContext();

            var anEvent = new Event();

            anEvent.WhenCreated = DateTime.Now;



            anEvent.Booking = db.Bookings.Find(4);

            long customerID = anEvent.Booking.CustomerID;

            //get other vars
            Customer aCustomer = db.Customers.Where(x => x.CustomerID == customerID).FirstOrDefault();


            EventCommandCreateDocument docEventCommand = new EventCommandCreateDocument(anEvent, aCustomer, PRCDocument.PRCDocumentType.UK_AirportTransfer, anEvent.Booking);

            anEvent.EventCommands.Add(docEventCommand);

            var result = new EventCommandResult();

            foreach (var command in anEvent.EventCommands)
            {
                result = command.ExecuteCommand();
            }

            //all done, do the logging

            var eventLogger = new EventLogger(db, new CommandLogger(db));

            eventLogger.LogEventAndCommandandCommandResult(anEvent, docEventCommand,
                                                           result);
        }
        public MaintainanceMailer()
        {
            //set some defaults
            using (var db = new PortugalVillasContext())
            {
                var toAddress = db.PRCInformations.First().PRCNotificationEmailAddress;

                ToEmailAddress = toAddress;
                EmailSubject   = @"PRC Maintainence Emailer";


                //create the message
                theAsposeMessage      = new MailMessage();
                theAsposeMessage.From = FromEmailAddress;
                theAsposeMessage.To   = ToEmailAddress;
                //  theAsposeMessage.To.Add("*****@*****.**");
                //  theAsposeMessage.To.Add("*****@*****.**");

                theAsposeMessage.Subject = EmailSubject;

                //set some email body


                //add the attachment
                // Attachment theMailAttachment = new Attachment(@"c:\temp\testfile.txt");
                //  theAsposeMessage.Attachments.Add(theMailAttachment);

                //set smtp vars
                theSMTPClient.Host         = "smtp.gmail.com";
                theSMTPClient.Username     = LoginEmailAddress;
                theSMTPClient.Password     = EmailPassword;
                theSMTPClient.Port         = 587;
                theSMTPClient.EnableSsl    = true;
                theSMTPClient.SecurityMode = SmtpSslSecurityMode.Explicit;
            }
        }
示例#22
0
        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";
                    }
                    else
                    {
                        EventTypeID = "20";
                    }

                    //email all docs
                    var form = new FormCollection();
                    form.Add("BookingID", booking.BookingID.ToString());
                    form.Add("EventTypeID", EventTypeID);

                    eventService.AddBookingEvent(form);

                    //email the user of the system
                }


                foreach (var bes in bookingExtraSelections)
                {
                    //link to parent booking
                }


                //wipe cars = booking and bes
                Session["Cart_PropertyBookings"] = null;
                Session["Cart_ExtraBookings"]    = null;


                return(RedirectToAction("EndOfBookingProcess", "EndOfProcess"));
            }
        }
示例#23
0
        //helper method for building the query - if the passed param not null
        //(object or string or zero (int or long or decimal)  the


        public List <Property> SearchForMatchingProperties()
        {
            PortugalVillasContext _db = new PortugalVillasContext();

            this.propertyQuery = _db.Properties.Include(x => x.PropertyTown);

            propertyQuery = propertyQuery.Where(x => x.Active == true);

            //test if each the object is not null or zero then add a where clause
            if (this.PropertyTypeID.HasValue && this.PropertyTypeID != 0)
            {
                propertyQuery = propertyQuery.Where(x => x.PropertyTypeID == this.PropertyTypeID);
            }

            if (this.VacationTypeID.HasValue && this.VacationTypeID != 0)
            {
                propertyQuery = propertyQuery.Where(x => x.PropertyVacationTypeID == this.VacationTypeID);
            }

            if (!String.IsNullOrEmpty(this.PoolType))
            {
                propertyQuery = propertyQuery.Where(x => x.SwimmingPoolType == this.PoolType);
            }

            if (this.MaxSleeps != 0)
            {
                propertyQuery = propertyQuery.Where(x => x.MaxGuests >= this.MaxSleeps);
            }
            //implicit zero
            else if (MaxSleeps == 0 && ((NoOfAdults + NoOfChildren + NoOfInfants) > 0))
            {
                //there's some people, need a house big enough for them AND infants if they have
                if (NoOfInfants > 0)
                {
                    //add infants claaus
                    propertyQuery = propertyQuery.Where(x => x.Cots > 0);
                }


                //add where clause for total people
                var totalPeople = NoOfAdults + NoOfChildren + NoOfInfants;
                propertyQuery = propertyQuery.Where(x => x.MaxGuests >= totalPeople - NoOfInfants);
            }



            //run the search and bring back some properties
            List <Property> theResultsList = new List <Property>();

            theResultsList = propertyQuery.ToList();



            if (this.TheSearchPriceRange != null) //check it's not null i.e. that there was a price range passed
            {
                if ((this.TheSearchPriceRange.MaxPrice != 2000 | this.TheSearchPriceRange.MinPrice != 1))
                {
                    //we want to search on price because a value has been provided, so create price ranges for active properties
                    //NB - NOW done in PriceRange.IsPropertyWithinPriceRange


                    List <Property> theResultsListWithPrice = new List <Property>();


                    foreach (var property in theResultsList)
                    {
                        if (PriceRange.IsPropertyWithinPriceRange(property, TheSearchPriceRange))
                        {
                            theResultsListWithPrice.Add(property);
                        }
                    }


                    return(theResultsListWithPrice);
                }
            }


            //no price search, just return the list
            return(theResultsList);
        }
示例#24
0
        public void TestFullDocumentGenerateStack()
        {
            var db = new PortugalVillasContext();

            //Test WITH PARENT

            //TEST WITH BOOKING
            Booking booking = db.Bookings.Where(x => x.BookingID.Equals(4)).FirstOrDefault();

            booking.PropertyID = 221;
            /*           Booking booking = null;*/



            //TEST WITH CUSTOMER
            Customer aCustomer = db.Customers.Where(x => x.CustomerID == 1).FirstOrDefault();
            //TEST WITH BES
            var bes = db.BookingExtraSelections.Where(x => x.BookingExtraSelectionID == 3).First();

            bes.BookingExtraID = 1;

            //set up vars


            var type = PRCDocument.PRCDocumentType.UK_WineTasting;



            //create event  - need to give it type thus name
            var anEvent = new Event();

            anEvent.Documents = new List <Document>();
            //TEST ADD ID - PLEASE REMOVE
            anEvent.EventID = 2;
            //END TEST CODE

            anEvent.WhenCreated = DateTime.Now;
            var commandsAndResultsToLog = new List <EventCommand>();


            //create correct command
            //doc
            //email out with doc

            EventCommandCreateDocument createDocCommand;
            EventCommandSendEmail      sendEmail;

            //HOW DO WE DECIDE WHAT TYPE OF EVENT WE WANT??? depends on type??

            if (booking != null)
            {
                createDocCommand = new EventCommandCreateDocument(anEvent, aCustomer, type, booking);
                /* sendEmail = new EventCommandSendEmail(anEvent, aCustomer, booking);*/
            }
            else
            {
                createDocCommand = new EventCommandCreateDocument(anEvent, aCustomer, type, null, bes);
                /*/sendEmail = new EventCommandSendEmail(anEvent, aCustomer, null, bes);*/
            }



            //create all commands
            anEvent.EventCommands.Add(createDocCommand);
            /*       anEvent.EventCommands.Add(sendEmail);*/


            //create document using executes
            var result = new EventCommandResult();

            foreach (var command in anEvent.EventCommands)
            {
                command.EventCommandResults.Add(command.ExecuteCommand());
                commandsAndResultsToLog.Add(command);
            }

            //render

            //save to DB with all correct commands etc

            var EventCommandLogger = new CommandLogger(db);
            var eventLogger        = new EventLogger(db, EventCommandLogger);

            //save event
            eventLogger.LogEvent(anEvent);
            //save eventcoomand and result


            foreach (var commandAndResult in commandsAndResultsToLog)
            {
                EventCommandLogger.Log(anEvent.EventID, commandAndResult);
            }

            //save document generated

            //NEED TO ADD CORRECT PARAMS (which are what??)

            //if there's any docs, write them to the DB
            foreach (var doc in anEvent.Documents)
            {
                doc.EventID             = anEvent.EventID;
                doc.DocumentDescription = type.ToString();
                doc.EmailTo             = aCustomer.EmailAddress;
                doc.CustomerID          = aCustomer.CustomerID;

                db.Documents.Add(doc);
                db.SaveChanges();
            }
        }
示例#25
0
        public List <BookingParticipant> CreateBookingParticipant(List <BookingParticipant> bookingParticipants, Booking booking, PortugalVillasContext db)
        {
            //assign fields

            foreach (var bookingParticipant in bookingParticipants)
            {
                bookingParticipant.BookingID = booking.BookingID;
                bookingParticipant.BookingParticipantWhenCreated = DateTime.Now;

                //GeneralStaticHelperMethods.IsPersonAdultChildOrInfant(bookingParticipant);

                db.BookingParticipants.Add(bookingParticipant);
            }
            db.SaveChanges();

            return(bookingParticipants);
        }
示例#26
0
        public CustomerBankDetail CreateCustomerBankDetail(CustomerBankDetail customerBankDetail, Customer customer, PortugalVillasContext db)
        {
            customer.CustomerID = customer.CustomerID;

            db.CustomerBankDetails.Add(customerBankDetail);
            //whack it in the session
            if (db.SaveChanges() > 0)
            {
                //customer now has an ID if the save has worked
            }



            return(customerBankDetail);
        }
示例#27
0
        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();
                    return(bookingExtraSelection);
                }
            }
            throw new Exception();
        }
示例#28
0
        public Booking CreateBooking(Booking booking, Property property, Customer theCustomer, PortugalVillasContext db)
        {
            //set default currency

            booking.BookingCurrencyConversionSymbol = theCustomer.PreferredCurrencySymbol;
            booking.BookingPreferredCurrency        = theCustomer.PreferredCurrency;

            var cc = new CurrencyConverterController();



            //if the booking is not in GBP convert to EUROS



            //NEED TO CONVERT THE CURRENCY BASED ON WHETHER IT NEEDS TO BE EU OR UK



            int adults, kids, infants;

            adults  = booking.NumberOfAdults ?? 0;
            kids    = booking.NumberOfChildren ?? 0;
            infants = booking.NumberOfInfants ?? 0;


            booking.NumberOfAdults   = adults;
            booking.NumberOfChildren = kids;
            booking.NumberOfInfants  = infants;



            booking.CustomerID    = theCustomer.CustomerID;
            booking.BookingTypeID = 1; //always a property booking

            booking.NumberOfGuests      = adults + kids + infants;
            booking.TotalNumberOfMinors = kids + infants;
            booking.NumberOfNights      = GeneralStaticHelperMethods.CalculateNoofNights(booking.StartDate, booking.EndDate);


            try
            {
                var exchangeRateFromDB = new CurrencyExchange();
                var baseCurrency       = "";
                var newCurrency        = "";

                booking.NumberOfNights = GeneralStaticHelperMethods.CalculateNoofNights(booking.StartDate,
                                                                                        booking.EndDate);
                booking.CalculateBookingPricingForAPropertyBooking(db);
                booking.CalculateExtrasPriceForAPropertyBooking(property, booking, db);
                //set this now because need to convert it
                booking.SetBreakageDepositDueDate(); //1 month before
                booking.SetBreakageDepositAmount();  //depends on property

                booking.BookingCurrencyLongName = "G.B. Pounds Sterling";
                //NOW CONVERT CURRENCY IF NECESSARY SO OTHER CALCS ARE CORRECT
                //CHANGE THIS!!! IT'S USING HIDDEN EXTERNAL DEPENDENY
                booking.BookingCurrencyConversionSymbol = "£";
                booking.BookingCurrencyExchangeRate     = 1.00M;
                booking.BookingPreferredCurrency        = "GBP";


                if (theCustomer.Country.ToLower() != "united kingdom" && ConfigurationManager.AppSettings["defaultCurrency"] == "GBP")
                {
                    //euro strategy
                    baseCurrency = "GBP";
                    newCurrency  = "EUR";


                    //set exchange rate
                    booking.BookingCurrencyExchangeRate     = exchangeRateFromDB.CurrencyExchangeRate;
                    booking.BookingCurrencyLongName         = "Euros";
                    booking.BookingCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol;
                    booking.BookingCurrencyExchangeRate     = exchangeRateFromDB.CurrencyExchangeRate;
                    booking.BookingPreferredCurrency        = "EUR";

                    try
                    {
                        booking.BookingPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.BookingPrice);
                        booking.BookingCurrencyConversionPrice = booking.BookingPrice;

                        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);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                //ALL BOOKINGS FOR US SYSTEM IN USD
                else if (ConfigurationManager.AppSettings["defaultCurrency"] == "USD")
                {
                    baseCurrency = "GBP";
                    newCurrency  = "USD";

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

                    //set exchange rate and currencies
                    booking.BookingCurrencyExchangeRate     = exchangeRateFromDB.CurrencyExchangeRate;
                    booking.BookingCurrencyLongName         = "U.S. Dollars";
                    booking.BookingCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol;
                    booking.BookingCurrencyExchangeRate     = exchangeRateFromDB.CurrencyExchangeRate;
                    booking.BookingPreferredCurrency        = "USD";
                }

                //do all cuurency conversions if not a UK booking
                if (theCustomer.Country.ToLower() != "united kingdom" || !ConfigurationManager.AppSettings["defaultCurrency"].Equals("GBP"))
                {
                    try
                    {
                        booking.BookingPrice = cc.ConvertCurrency(baseCurrency, newCurrency,
                                                                  (decimal)booking.BookingPrice);
                        booking.BookingCurrencyConversionPrice = booking.BookingPrice;

                        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);
        }
 public EventFactory(PortugalVillasContext context)
 {
     context = context;
 }
        //  [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"));
        }