Ejemplo n.º 1
0
        public async Task <IActionResult> Tweeter(Tweet t)
        {
            using (var context = new TweetifyContext())
            {
                t.Content = t.Content.ToLower();
                context.Tweets.Add(t);
                await context.SaveChangesAsync();

                return(RedirectToAction("Login"));
            }
        }
        public async Task <ActionResult> Index(Tweet t)
        {
            try
            {
                using (var context = new TweetifyContext())
                {
                    t.Author = context.Users.FirstOrDefault(x => x.Id == HttpContext.Session.GetInt32("UserId"));
                    await context.Tweets.AddAsync(t);

                    await context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Tweeter(Tweet tweeter)
        {
            if (!HttpContext.Session.GetInt32("UserId").HasValue)
            {
                return(RedirectToAction("Login", "Auth"));
            }
            else
            {
                using (var con = new TweetifyContext())
                {
                    tweeter.Date   = DateTime.Now;
                    tweeter.Author = con.Users.FirstOrDefault(a => a.Id == HttpContext.Session.GetInt32("UserId"));
                    await con.Tweets.AddAsync(tweeter);

                    await con.SaveChangesAsync();
                }
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 4
0
        public async Task<IActionResult> Register(User u)
        {
            using (var context = new TweetifyContext())
            {
                User temp = context.Users.FirstOrDefault(x => x.Username == u.Username);

                if (temp != null)
                {
                    throw new Exception("User all ready exists");
                }
                else
                {
                    u.Username = u.Username.ToLower();
                    context.Users.Add(u);
                    await context.SaveChangesAsync();
                    return RedirectToAction("Login");
                }
            }
        }