コード例 #1
0
        public string Login(AccountCredentials account)
        {
            //Check account existance
            #region Check User

            int Id = WebSecurity.GetUserId(account.username);

            CardiologistV2.DAL.DatabaseContext db = new CardiologistV2.DAL.DatabaseContext();
            CardiologistV2.Models.Patient      p  = db.Patients.Find(Id);

            #endregion

            if (p != null)
            {
                //Authenticate user and return ID to Client

                bool response = WebSecurity.Login(account.username, account.password);
                if (response)
                {
                    return("200|" + p.PatientID);
                }

                else
                {
                    return("422|Request Could not be Processed");
                }
            }

            else
            {
                return("400|Bad Request");
            }
        }
コード例 #2
0
        public string register(ServerApp.Models.Patient patient, AccountCredentials account)
        {
            /////
            #region Create User Account
            WebSecurity.CreateUserAndAccount(account.username, account.password);

            #endregion

            #region Add User to Role 'Patient'
            bool     pat_role = false;
            string[] roles    = Roles.GetAllRoles();
            for (int i = 0; i < roles.Length; i++)
            {
                if (roles[i] == "Patient")
                {
                    pat_role = true; break;
                }
            }
            if (pat_role == false)
            {
                Roles.CreateRole("Patient");
            }
            Roles.AddUsersToRole(new[] { account.username }, "Patient");
            #endregion

            #region Save Patient
            CardiologistV2.DAL.DatabaseContext db = new CardiologistV2.DAL.DatabaseContext();
            db.Users.Add(new CardiologistV2.Models.User()
            {
                UserID = WebSecurity.GetUserId(account.username)
            });

            var p = new CardiologistV2.Models.Patient();
            p.PatientID   = WebSecurity.GetUserId(account.username);
            p.Name        = patient.Name;
            p.DateOfbirth = patient.DOB;
            p.Gender      = patient.Gender;
            p.Address     = patient.Address;
            p.Job         = patient.Job;
            p.Smoker      = patient.Smoker;
            p.Alcoholic   = patient.Alcoholic;
            db.Patients.Add(p);

            db.SaveChanges();
            #endregion

            /////

            return("200");
        }