Пример #1
0
        /// <summary>
        /// Transforms the object to the database schema object that can be persisted.
        /// </summary>
        /// <returns>Returns the transformed database schema object.</returns>
        public static analytic GetDatabaseModel(AnalyticsModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            analytic record = new analytic();

            record.NewUser             = model.NewUser;
            record.IsAuthenticated     = model.IsAuthenticated;
            record.AuthenticatedUserId = model.AuthenticatedUserId;
            record.SessionId           = model.SessionId;
            record.BrowserId           = model.BrowserId;

            record.PageUrl         = model.PageUrl;
            record.PageTitle       = model.PageTitle;
            record.ServerTimeStamp = model.ServerTimeStamp.DateTime;

            record.cmp_name   = model.CampaignName;
            record.cmp_ref    = model.CampaignReferrer;
            record.cmp_source = model.CampaignSource;

            record.IPAddress  = model.IPAddress;
            record.UserAgent  = model.UserAgent;
            record.DeviceType = model.DeviceType;

            record.EventId   = model.EventId;
            record.EventType = model.EventType;
            record.EventInfo = model.EventInfo;

            record.FlightId = model.FlightId;
            return(record);
        }
Пример #2
0
 public ActionResult View(int id)
 {
     using (rvcaEntities db = new rvcaEntities())
     {
         analytic item = db.analytics.FirstOrDefault(x => x.id == id);
         if (item == null)
         {
             item = new analytic();
         }
         return(View("ViewAnalytics", item));
     }
 }
Пример #3
0
        // GET: AnalyticResults/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            analytic analytic = db.analytics.Find(id);

            if (analytic == null)
            {
                return(HttpNotFound());
            }
            return(View(analytic));
        }
        public ActionResult IncrementRedirect(Result result)
        {
            int      count      = 0;
            bool     exists     = false;
            analytic dbAnalytic = null;
            hit      dbhit      = null;

            //Find out if it exists
            using (var db = new iTunesSearchEntities())
            {
                count = db.analytics.Count();

                //if the value exists, update
                if (db.hits.Any(a => a.url == result.ViewURL))
                {
                    exists     = true;
                    dbAnalytic = db.analytics.Where(a => a.hit.url == result.ViewURL).FirstOrDefault <analytic>();
                }
                else  //otherwise add new hit to database
                {
                    exists = false;

                    dbhit = new hit
                    {
                        trackId    = ++count,
                        url        = result.ViewURL,
                        title      = result.TrackName,
                        artist     = result.ArtistName,
                        artworkurl = result.ArtworkURL100,
                    };

                    db.hits.Add(dbhit);
                    db.SaveChanges();
                }
            }

            //change without DBContext or create
            if (exists && dbAnalytic != null)
            {
                dbAnalytic.hitCount++;
            }
            else
            {
                dbAnalytic = new analytic
                {
                    trackId  = count,
                    hitCount = 1,
                    //hit = dbhit,
                };
            }

            using (var db = new iTunesSearchEntities())
            {
                if (exists)
                {
                    db.Entry(dbAnalytic).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    db.analytics.Add(dbAnalytic);
                }

                db.SaveChanges();
            }

            return(Redirect(result.ViewURL));
        }