예제 #1
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;
        }
예제 #2
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");
 }
예제 #3
0
        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);
        }