Esempio n. 1
0
        public List <Models.ViewTag> Get()
        {
            CrowdHippoEntities db = new CrowdHippoEntities();
            var tags = new List <Models.ViewTag>();

            //
            foreach (Tag tag in db.Tags.ToList())
            {
                var viewTag = new ViewTag()
                {
                    Id   = tag.Id,
                    Name = tag.Name
                           //
                };
                switch (tag.Id)
                {
                case 1: viewTag.Color = "Red"; break;

                case 2: viewTag.Color = "Green"; break;

                case 3: viewTag.Color = "Blue"; break;

                case 4: viewTag.Color = "Purple"; break;
                }
                tags.Add(viewTag);
            }
            return(tags);
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Hometown = model.Hometown
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                //
                CrowdHippoEntities db = new CrowdHippoEntities();
                db.Users.Add(new User()
                {
                    UserId = user.Id
                });
                db.SaveChanges();
                //
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 3
0
        public Models.Keywords get(int tweetid)
        {
            CrowdHippoEntities db = new CrowdHippoEntities();
            var keywords          = new List <Keyword>();

            //
            keywords = db.Keywords.Where(key => key.TweetId == tweetid).ToList();
            var results = new Models.Keywords();

            foreach (Keyword k in keywords)
            {
                Models.Keyword item = new Models.Keyword();
                item.Id       = k.Id;
                item.Name     = k.Keyword1;
                item.TagCount = 0;
                //
                switch (k.SourceId)
                {
                case 1: results.fromText.Add(item);
                    break;

                case 2: results.fromHashtag.Add(item);
                    break;

                case 3: results.fromURL.Add(item);
                    break;
                }
            }
            return(results);
        }
        private Tweet PickTweet(List <Tweet> omitList)
        {
            Tweet newPick = null;

            using (CrowdHippoEntities db = new CrowdHippoEntities())
            {
                //
                var notfound = true;
                int counter  = 0;
                while (notfound)
                {
                    int id = new Random().Next(db.Tweets.Count());
                    newPick = db.Tweets.ToList().ElementAt(id);
                    if (!omitList.Any(ol => ol.Id == newPick.Id))
                    {
                        if (!newPick.Keywords.Any(k => k.UserKeywordTags.Count() > 0))
                        {
                            notfound = false;
                        }
                    }
                    //
                    counter++;
                    if (counter == 20)
                    {
                        notfound = false;
                    }
                }
            }
            //
            return(newPick);
        }
        public List <Models.Tweet> get()
        {
            try
            {
                CrowdHippoEntities  db     = new CrowdHippoEntities();
                List <Models.Tweet> tweets = new List <Models.Tweet>();
                //var skip = new Random().Next(db.Tweets.Count());
                //if (skip >= db.Tweets.Count() - 15)
                //    skip = 1;
                //var tList = db.Tweets.OrderBy(x=>x.Id).Skip(skip).Take(15).ToList();
                var tList = new List <Tweet>();
                for (int i = 0; i <= 15; i++)
                {
                    tList.Add(PickTweet(tList));
                }

                //tList = db.Tweets.OrderBy(x => x.Id).Take(15).ToList();
                foreach (Tweet t in tList)
                {
                    Models.Tweet tw = new Models.Tweet()
                    {
                        Id   = t.Id,
                        Text = t.Text
                    };
                    tweets.Add(tw);
                }
                return(tweets);
            }
            catch (Exception ex)
            {
                var message = ex.Message;
            }
            return(null);
        }
 public void Post(List<Models.KeywordTags> keywordTags)
 {
     using (CrowdHippoEntities db = new CrowdHippoEntities())
     {
         var username = (string)HttpContext.Current.Session["username"];
         var user=  db.AspNetUsers.Where(us => us.UserName == username).FirstOrDefault();
         var existingTags = db.UserKeywordTags.ToList();
         if(user != null)
         {
             var internalUser = db.Users.Where(us => us.UserId == user.Id).FirstOrDefault();
             if(internalUser != null)
             {
                 foreach(Models.KeywordTags kt in keywordTags)
                 {
                     if (!existingTags.Exists(et => et.KeywordId == kt.KeywordId && et.TagId == kt.TagId && et.UserId == internalUser.Id))
                     {
                         UserKeywordTag ukt = new UserKeywordTag()
                         {
                             KeywordId = kt.KeywordId,
                             TagId = kt.TagId,
                             UserId = internalUser.Id
                         };
                         db.UserKeywordTags.Add(ukt);
                     }
                 }
                 db.SaveChanges();
             }
         }
     }
 }
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Hometown = model.Hometown
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        CrowdHippoEntities db = new CrowdHippoEntities();
                        db.Users.Add(new User()
                        {
                            UserId = user.Id
                        });
                        db.SaveChanges();
                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
 public Models.Tweet get(int id)
 {
     try
     {
         CrowdHippoEntities db = new CrowdHippoEntities();
         var tweet             = db.Tweets.Where(t => t.Id == id).FirstOrDefault();
         var tw = new Models.Tweet()
         {
             Id   = tweet.Id,
             Text = tweet.Text
         };
         return(tw);
     }
     catch (Exception ex)
     {
         var message = ex.Message;
     }
     return(null);
 }