public ActionResult Edit(ClickCounter clickcounter)
 {
     if (ModelState.IsValid)
     {
         context.Entry(clickcounter).State = EntityState.Modified;
         context.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.PossibleUsers = context.Users;
     return View(clickcounter);
 }
Ejemplo n.º 2
0
        public IEnumerable<ClickCounter> SimulateClicks(int userId, int Category, int count, Func<DateTime> dateTimeGenerator, Func<Coordinates> locationGenerator)
        {
            var list = new List<ClickCounter>();
            Random rnd = new Random();
            IEnumerable<int> indexes = new List<int>();
            var newsFiles = context.NewsFiles;
            var categories = context.Categories;
            var rows = CategoryHelpers.getRowsByCategory(newsFiles, Category, categories).OrderBy(x => new Guid()).Take(count).ToList();
            foreach (var r in rows)
            {
                var location = locationGenerator();
                var click = new ClickCounter { CategoryId = r.CategoryId, ClickDate = dateTimeGenerator(), NewsId = r.NewsId, UserId = userId};
                click.SetLocation(location);
                click.SetDayOfWeekAndTimeOfDay();
                list.Add(context.Clicks.Add(click));
            }

            context.SaveChanges();
            return list;
        }
Ejemplo n.º 3
0
        public String Click(DateTime ClickDate, String token, int? newsId, Coordinates coordinates = null)
        {
            if (ClickDate!=null&&token!=null&&newsId!=null)
            {
                var categoryId = context.NewsFiles.Where(x => x.NewsId == newsId.Value).Select(x => x.CategoryId).First();
                Guid g = Guid.Parse(token);
                var userId = context.Users.Where(x => x.AccessToken == g).First().UserId;
                var click = new ClickCounter { UserId = userId, ClickDate = ClickDate, CategoryId = categoryId, NewsId = newsId.Value };
                if(coordinates!=null && (coordinates.Latitude==0 && coordinates.Longitude==0)){
                    coordinates=null;
                }
                click.SetLocation(coordinates);
                click.SetDayOfWeekAndTimeOfDay();
                context.Clicks.Add(click);
                context.SaveChanges();
                return "Click saved";
            }

            return "Bad info";
        }