示例#1
0
 public static App_User_Profiles Get_App_User_Profile()
 {
     var app_model = new App_Model();
     if (HttpContext.Current.User.Identity.IsAuthenticated)
     {
         string app_user_id = HttpContext.Current.User.Identity.GetUserId();
         try
         {
             return app_model.App_User_Profiles.Where(up => up.app_user_id == app_user_id).Single<App_User_Profiles>();
         }
         catch { throw new Exception("Can't find this User Profile."); }
     }
     return null;
 }
示例#2
0
        public ActionResult Index()
        {
            //ViewBag.ReturnUrl = Request.RawUrl;
            var app_model = new App_Model();
            ViewData["user_profile"] = User_Utils.Get_App_User_Profile();
            /*if (User.Identity.IsAuthenticated)
            {
                string app_user_id = User.Identity.GetUserId();
                ViewData["user_profile"] = app_model.App_User_Profiles.Where(up => up.app_user_id == app_user_id).Single();
            }*/
            ViewData["areas"] = app_model.App_Areas;

            return View();
        }
示例#3
0
        public static bool AreaMemberships_AddEdit(int area_id, int membership_type_id, int user_id = 0, int id=0)
        {
            var app_model = new App_Model();

            App_User_Profiles user_profile = User_Utils.Get_App_User_Profile();
            if (!(user_id > 0)) {
                user_id = user_profile.id;
            }
            App_Areas area = app_model.App_Areas.Where(a => a.id == area_id).Single<App_Areas>();
            if(area.requirement_age != null){
                if (User_Utils.Calc_Age(user_profile.birthdate) < area.requirement_age)
                    throw new Exception("Not of appropriate age.");
            }

            App_User_Area_Memberships item = null;
            if (id > 0)
                item = app_model.App_User_Area_Memberships.Find(id);
            else
                item = new App_User_Area_Memberships();

            if (item != null)
            {
                item.area_id = area_id;
                item.membership_type_id = membership_type_id;
                item.user_id = user_id;
                if (!(id > 0))
                    app_model.App_User_Area_Memberships.Add(item);

                //Check # of shop stewards
                App_Membership_Types member_type_steward = app_model.App_Membership_Types.Where(mt => mt.title == "Shop Steward").Single();
                if (member_type_steward.id == membership_type_id)
                {
                    if (app_model.App_User_Area_Memberships.Where(uam => (uam.area_id == area_id) && (uam.membership_type_id == member_type_steward.id)).Count() > 0)
                        throw new Exception("Too many Stewards. Only 1 allowed. You may need to demote someone.");

                }

                try
                {
                    app_model.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new Exception("User is already a member.");

                }
            }
            return true;
        }
示例#4
0
 // GET: /Manage/AreaMemberships_Delete
 public ActionResult AreaMemberships_Delete(int id)
 {
     var app_model = new App_Model();
     App_User_Area_Memberships user_area_membership = app_model.App_User_Area_Memberships.Find(id);
     app_model.App_User_Area_Memberships.Remove(user_area_membership);
     app_model.SaveChanges();
     return RedirectToAction("AreaMemberships", "Manage");
 }
示例#5
0
 // GET: /Manage/AreaMemberships_GetDetails
 public ActionResult AreaMemberships_EditDetails(int? id)
 {
     var app_model = new App_Model();
     ViewData["areas"] = app_model.App_Areas;
     ViewData["membership_types"] = app_model.App_Membership_Types;
     ViewData["users"] = app_model.App_User_Profiles;
     return View(app_model.App_User_Area_Memberships.Find(id));
 }
示例#6
0
 // GET: /Manage/AreaMemberships
 public ActionResult AreaMemberships()
 {
     var app_model = new App_Model();
     return View(app_model.App_User_Area_Memberships);
 }
示例#7
0
        public ActionResult AreaJoinAsMember(AreaJoinAsMemberModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }


            var app_model = new App_Model();
            App_Membership_Types membership_type = app_model.App_Membership_Types.Where(amt => amt.title == "Member").Single<App_Membership_Types>();
            try
            {
                User_Utils.AreaMemberships_AddEdit(model.area_id, membership_type.id);
            }
            catch (Exception e)
            {
                ViewBag.Error_Message = e.Message;
                return View("Error");
            }
            
            return RedirectToAction("Index", "Home");
            //return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                DateTime bday = DateTime.MinValue;
                if (model.Birthdate_Year > 1900)
                {
                    try
                    {
                        bday = new DateTime(model.Birthdate_Year, model.Birthdate_Month, model.Birthdate_Day);
                    }
                    catch { }
                }
                if (bday == DateTime.MinValue)
                {
                    AddErrors(new IdentityResult("Invalid Birthdate"));
                    return View(model);
                }

                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    //Add User to a Profile.
                    App_Model app_model = new App_Model();
                    
                    app_model.App_User_Profiles.Add(
                        new App_User_Profiles { name = model.Name, birthdate = bday, app_user_id = user.Id }
                    );
                    app_model.SaveChanges();
                    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);
        }