public ActionResult EditMember(int communityId, int personId) { List <Role> roles = CommunityShedData.GetRoles(personId, communityId); bool approver = false; bool reviewer = false; bool enforcer = false; foreach (var role in roles) { if (role.Name == "Approver") { approver = true; } if (role.Name == "Reviewer") { reviewer = true; } if (role.Name == "Enforcer") { enforcer = true; } } CommunityEditMemberViewModel viewModel = new CommunityEditMemberViewModel { Community = CommunityShedData.GetCommunity(communityId), Approver = approver, Reviewer = reviewer, Enforcer = enforcer }; return(View(viewModel)); }
public ActionResult Register(RegisterViewModel viewModel) { // TODO Check if email exists in database CommunityShedData.RegisterUser(viewModel); FormsAuthentication.SetAuthCookie(viewModel.EmailAddress, false); return(RedirectToAction("Index", "Home")); }
public ActionResult List() { CommunityListViewModel viewModel = new CommunityListViewModel { Communities = CommunityShedData.GetCommunityListItems(CustomUser.Person.Id) }; return(View(viewModel)); }
public ActionResult Edit(Community community) { if (ModelState.IsValid && CustomUser.CanEditCommunity(community.Id)) { CommunityShedData.UpdateCommunity(community); return(RedirectToAction("Details", "Community", routeValues: new { communityId = community.Id })); } return(View(community)); }
public ActionResult Join(int communityId) { CommunityJoinViewModel viewModel = new CommunityJoinViewModel() { CommunityName = CommunityShedData.GetCommunity(communityId).Name, Success = CommunityShedData.JoinCommunity(communityId, CustomUser.Person.Id) }; return(View(viewModel)); }
public ActionResult Add(Community community) { if (ModelState.IsValid) { // TODO redirect to details page CommunityShedData.AddCommunity(community, CustomUser.Person.Id); return(RedirectToAction("Index", "Home")); } return(View(community)); }
public ActionResult Edit(int communityId) { if (CustomUser.CanEditCommunity(communityId)) { Community community = CommunityShedData.GetCommunity(communityId); return(View(community)); } else { return(RedirectToAction("Index", "Home")); } }
// GET: Home public ActionResult Index() { HomeViewModel viewModel = new HomeViewModel { BorrowedItems = new List <Item>(), UserItems = new List <Item>(), Communities = CommunityShedData.GetCommunities(CustomUser.Person.Id), CommunityRoles = CustomUser.Person.Roles }; return(View(viewModel)); }
public ActionResult Details(int communityId) { // Querying the database for each property can get expensive. CommunityDetailsViewModel viewModel = new CommunityDetailsViewModel { Community = CommunityShedData.GetCommunity(communityId), PersonRoles = CommunityShedData.GetCommunityPersonRoles(communityId), Members = CommunityShedData.GetCommunityMembers(communityId), CanEdit = CustomUser.CanEditCommunity(communityId), CanEditMembers = CustomUser.IsInRole("Enforcer", communityId) }; return(View(viewModel)); }
public ActionResult Login(LoginViewModel viewModel) { if (ModelState.IsValid) { if (ModelState.IsValidField("EmailAddress") && ModelState.IsValidField("Password")) { if (!CommunityShedData.AuthenticateUser(viewModel)) { ModelState.AddModelError("", "Invalid username or password."); } } if (ModelState.IsValid) { FormsAuthentication.SetAuthCookie(viewModel.EmailAddress, false); return(RedirectToAction("Index", "Home")); } } return(View(viewModel)); }
protected void Application_PostAuthenticateRequest() { IPrincipal user = HttpContext.Current.User; if (user.Identity.IsAuthenticated && user.Identity.AuthenticationType.Equals("Forms")) { FormsIdentity formsIdentity = (FormsIdentity)user.Identity; FormsAuthenticationTicket ticket = formsIdentity.Ticket; CustomIdentity customIdentity = new CustomIdentity(ticket); Person person = CommunityShedData.GetPrincipalPerson(ticket.Name); // Can incorporate this into CommunityShedData.GetPrincipalPerson() person.Roles = CommunityShedData.GetCommunityRoles(person.Id); CustomPrincipal customPrincipal = new Security.CustomPrincipal(customIdentity, person); HttpContext.Current.User = customPrincipal; Thread.CurrentPrincipal = customPrincipal; } }