Exemple #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
            }
        }
Exemple #2
0
        /*
         * Adds a pagevisit
         * Returns true if the pagevisit was inserted, false if no records were inserted
         * Throws DALException if something else went wrong
         */
        public Boolean add(PageVisits pageVisits)
        {
            SqlCommand command = null;

            using (var cnn = new SqlConnection(sDatabaseLocatie))
            {
                command = new SqlCommand("INSERT INTO PageVisits " +
                                         "(customer_id, dvd_info_id, number_of_visits) " +
                                         "VALUES(@customer_id, @dvd_info_id, @number_of_visits)", cnn);
                command.Parameters.Add(new SqlParameter("@customer_id", pageVisits.customer.customer_id));
                command.Parameters.Add(new SqlParameter("@dvd_info_id", pageVisits.dvdInfo.dvd_info_id));
                command.Parameters.Add(new SqlParameter("@number_of_visits", pageVisits.number_of_visits));

                try
                {
                    cnn.Open();
                    if (command.ExecuteNonQuery() > 0)
                    {
                        return(true);
                    }
                    return(false);
                }
                catch (Exception ex)
                {
                    throw new DALException("Failed to insert a pagevisit", ex);
                }
                finally
                {
                    if (cnn != null)
                    {
                        cnn.Close();
                    }
                }
            }
        }
 public Boolean updatePageVisits(PageVisits pageVisits)
 {
     if (pageVisits != null)
     {
         if (pageVisits.number_of_visits > 1)
         {
             return(new PageVisitsDAO().update(pageVisits));
         }
         else
         {
             return(new PageVisitsDAO().add(pageVisits));
         }
     }
     return(false);
 }
 public Boolean addPageVisits(PageVisits pageVisits)
 {
     return(new PageVisitsDAO().add(pageVisits));
 }