Ejemplo n.º 1
0
        /*Increases the number of pagevisits for this user and movie by one. Creates a new record if none currently exists.*/
        public void incrementPageVisits(Customer customer, DvdInfo dvdInfo)
        {
            PageVisits        pageVisits        = null;
            PageVisitsService pageVisitsService = new PageVisitsService();

            try
            {
                pageVisits = pageVisitsService.getByDvdAndCustomer(customer, dvdInfo);           //Throws NoRecordException
                pageVisits.number_of_visits += 1;
            }
            catch (NoRecordException)
            {
                pageVisits                  = new PageVisits();
                pageVisits.customer         = customer;
                pageVisits.dvdInfo          = dvdInfo;
                pageVisits.number_of_visits = 1;
            }
            catch (DALException)
            {
            }
            if (pageVisitsService.updatePageVisits(pageVisits))
            {
                //succes
            }
        }
        /**Returns a list of the most viewed pages.*/
        private List <DvdInfo> getMostViewedDvdInfos(Customer customer)
        {
            List <DvdInfo> dvdInfos = new List <DvdInfo>();

            try
            {
                DvdInfoService dvdInfoService = new DvdInfoService();

                List <PageVisits> pageVisitsList = new PageVisitsService().getTopPageVisitsForCustomer(customer, 16);          //Throws NoRecordException

                List <DvdInfo> dvdInfosFinal = new List <DvdInfo>();

                foreach (PageVisits pageVisits in pageVisitsList)
                {
                    dvdInfos.Add(dvdInfoService.getByID(pageVisits.dvdInfo.dvd_info_id.ToString()));           //Throws NoRecordException
                }

                //only return dvd's that the user hasn't bought before
                foreach (DvdInfo dvdInfo in dvdInfos)
                {
                    if (!orderLinesDvdIds.Contains(dvdInfo.dvd_info_id))
                    {
                        dvdInfosFinal.Add(dvdInfo);
                    }
                }
            }
            catch (DALException ex)
            {
                throw new NoRecordException("failed to retrieve data", ex);
            }
            catch (NoRecordException ex)
            {
            }
            return(dvdInfos);
        }