home controller

C#

Public Domain

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Twix.Models;

namespace Twix.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            if (Request.IsAuthenticated)
                return RedirectToAction("Member");

            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }
        [Authorize]
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult Member()
        {
            return View();
        }

        [Authorize]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Member(string status)
        {
            if (!string.IsNullOrEmpty(status))
            {
                using (var db = new twixDataContext())
                {
                    var statusUpdate = new StatusUpdate()
                    {
                        UserID = db.GetUserIdForUserName(User.Identity.Name),
                        Message = status
                    };

                    db.StatusUpdates.InsertOnSubmit(statusUpdate);
                    db.SubmitChanges();
                }
            }

            return RedirectToAction("Member");
        }

        public ActionResult About()
        {
            return View();
        }
    }
}