コード例 #1
0
        // not local student account, create one and return userId
        // local student account exist, return userId
        public int createStudentAccount(String email)
        {
            using (Youth_Center_DB_Conn db = new Youth_Center_DB_Conn())
            {
                try
                {
                    var dupicatedAccount = from user in db.ProjectLaucherSets
                                           where user.emailAddr.ToUpper().Equals(email.ToUpper())
                                           select user;
                    if (!dupicatedAccount.Any())
                    {
                        ProjectLaucherSet user = new ProjectLaucherSet();
                        user.emailAddr = email;
                        user.role = "Student";

                        ProjectLaucherSet_Student student = new ProjectLaucherSet_Student();
                        student.hasPersonalInfo = false;
                        student.canPost = true;
                        student.ProjectLaucherSet = user;

                        db.ProjectLaucherSet_Student.Add(student);
                        db.SaveChanges();
                        return user.Id;
                    }
                    else
                    {
                        return dupicatedAccount.First().Id;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                }
                return -1;
            }
        }
コード例 #2
0
        //
        //
        public ActionResult CreateAdmin()
        {
            try
            {
                string email = Request.Params["email"].Trim();
                string password = Request.Params["password"].Trim();

                var dupicatedEmail = from ad in db.ProjectLaucherSets
                                     where ad.emailAddr == email
                                     select ad;

                if (!dupicatedEmail.Any())
                {
                    ProjectLaucherSet laucher = new ProjectLaucherSet();
                    laucher.emailAddr = email;
                    laucher.role = "Admin";

                    ProjectLaucherSet_AdminSet admin = new ProjectLaucherSet_AdminSet();
                    admin.password = password;

                    admin.ProjectLaucherSet = laucher;
                    laucher.ProjectLaucherSet_AdminSet = admin;

                    db.ProjectLaucherSet_AdminSet.Add(admin);
                    db.SaveChanges();

                    return RedirectToAction("AdminAccountManagement", new { message = "an admin account has been added" });
                }
            }
            catch (Exception ex) { }

            return RedirectToAction("AdminAccountManagement");
        }
コード例 #3
0
        //
        //
        public int createExternalAccount(string email, string password, string name, string phone, string organization, string description)
        {
            using (Youth_Center_DB_Conn db = new Youth_Center_DB_Conn())
            {
                try
                {
                    var duplicatedEmail = from p in db.ProjectLaucherSets
                                          where p.emailAddr.ToUpper().Equals(email.ToUpper())
                                          select p;
                    if (!duplicatedEmail.Any())
                    {
                        ProjectLaucherSet laucher = new ProjectLaucherSet();
                        laucher.emailAddr = email;
                        laucher.role = "External_User";

                        ProjectLaucherSet_ExtenalUser externalUser = new ProjectLaucherSet_ExtenalUser();
                        externalUser.name = name;
                        externalUser.password = password;
                        externalUser.phoneNumber = phone;
                        externalUser.organization = organization;
                        externalUser.organizationDescription = description;
                        externalUser.ProjectLaucherSet = laucher;
                        externalUser.isDisabled = true;

                        db.ProjectLaucherSets.Add(laucher);
                        externalUser = db.ProjectLaucherSet_ExtenalUser.Add(externalUser);
                        db.SaveChanges();
                        return externalUser.Id;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                }
                return -1;
            }
        }