summaryrefslogtreecommitdiff
path: root/Project-Unite/Controllers/ProfilesController.cs
blob: a1d4235a556180fe93f185385a16439197b4e8fc (plain) (blame)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using Project_Unite.Models;

namespace Project_Unite.Controllers
{
    [Authorize]
    public class ProfilesController : Controller
    {
        // GET: Profiles
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ViewProfile(string id)
        {
            var db = new ApplicationDbContext();
            var user = db.Users.FirstOrDefault(x => x.DisplayName == id);
            if (user == null)
                return new HttpStatusCodeResult(404);

            return View(user);
        }

        public ActionResult PostContent(UserPost model)
        {
            var db = new ApplicationDbContext();
            model.Id = Guid.NewGuid().ToString();
            model.PostedAt = DateTime.Now;
            model.UserId = User.Identity.GetUserId();
            db.UserPosts.Add(model);
            db.SaveChanges();
            return RedirectToAction("ViewProfile", "Profiles", new { id = ACL.UserNameRaw(User.Identity.GetUserId()) });
            
        }
    }
}