public async Task <IHttpActionResult> GettXrefUserSHARESettingsPurpos(int id)
        {
            tXrefUserSHARESettingsPurpos tXrefUserSHARESettingsPurpos = await db.tXrefUserSHARESettingsPurposes.FindAsync(id);

            if (tXrefUserSHARESettingsPurpos == null)
            {
                return(NotFound());
            }

            return(Ok(tXrefUserSHARESettingsPurpos));
        }
        public async Task <IHttpActionResult> PosttXrefUserSHARESettingsPurpos(tXrefUserSHARESettingsPurpos tXrefUserSHARESettingsPurpos)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tXrefUserSHARESettingsPurposes.Add(tXrefUserSHARESettingsPurpos);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = tXrefUserSHARESettingsPurpos.ID }, tXrefUserSHARESettingsPurpos));
        }
        public async Task <IHttpActionResult> DeletetXrefUserSHARESettingsPurpos(int id)
        {
            tXrefUserSHARESettingsPurpos tXrefUserSHARESettingsPurpos = await db.tXrefUserSHARESettingsPurposes.FindAsync(id);

            if (tXrefUserSHARESettingsPurpos == null)
            {
                return(NotFound());
            }

            db.tXrefUserSHARESettingsPurposes.Remove(tXrefUserSHARESettingsPurpos);
            await db.SaveChangesAsync();

            return(Ok(tXrefUserSHARESettingsPurpos));
        }
        public async Task <IHttpActionResult> PuttXrefUserSHARESettingsPurpos(int id, tXrefUserSHARESettingsPurpos tXrefUserSHARESettingsPurpos)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tXrefUserSHARESettingsPurpos.ID)
            {
                return(BadRequest());
            }

            db.Entry(tXrefUserSHARESettingsPurpos).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tXrefUserSHARESettingsPurposExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 5
0
        public async Task <IHttpActionResult> RegisterUser(tUser tUser)
        {
            //tUser user = await db.tUsers.FirstAsync(x => x.Email == tUser.Email);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //var user = db.tUsers.FirstOrDefault(x => x.Email == tUser.Email);
            //if (user != null)
            //{
            //    return Conflict();
            //}

            try
            {
                tUser.ExternalID      = Guid.NewGuid();
                tUser.CreateDateTime  = DateTime.Now;
                tUser.AccountStatusID = 1;
                //tUser.PHSaltID = 1;

                if (tUser.PasswordHash != null)
                {
                    PasswordStorage oPassUtil = new PasswordStorage();
                    //oPassUtil.Hashstring = ;
                    oPassUtil.CreateHash(tUser.PasswordHash);
                    //oPassUtil.VerifyPassword
                    tUser.PasswordHash = oPassUtil.Hashstring;

                    tSalt salt = new tSalt();
                    salt.Salt = oPassUtil.Saltstring;

                    SaltsController sl = new SaltsController();
                    tUser.tSalt = await sl.PosttSalt(salt);

                    tUser.PHSaltID = tUser.tSalt.Id;
                }

                db.tUsers.Add(tUser);
                db.SaveChanges();

                //post new userid to other dbs
                UserData.UserIDsController userIds = new UserData.UserIDsController();
                tUserID userID = new tUserID();
                userID.UserID = tUser.ID;

                await userIds.PosttUserID(userID);

                WebApp.UserIDsController webUsers = new WebApp.UserIDsController();
                await webUsers.PosttUserID(userID);

                //Add default consent to new user's share settings
                tUserSHARESetting            userSHARESetting = new tUserSHARESetting();
                tXrefUserSHARESettingsPurpos userXrefSHARE    = new tXrefUserSHARESettingsPurpos();
                userSHARESetting.AllData        = true;
                userSHARESetting.UserID         = tUser.ID;
                userSHARESetting.SHARESettingID = 1; //allow
                userSHARESetting.SystemStatusID = 1; //valid
                userXrefSHARE.SHARESettingID    = userSHARESetting.ID;
                userXrefSHARE.SHAREPurposeID    = 2; //Research only, any available
                userSHARESetting.tXrefUserSHARESettingsPurposes.Add(userXrefSHARE);

                UserData.UserSHARESettingsController shareController = new UserData.UserSHARESettingsController();
                await shareController.PosttUserSHARESetting(userSHARESetting);

                //return CreatedAtRoute("UsersAPI", new { id = tUser.ID }, tUser);
                return(Ok(tUser));
            }
            catch (Exception ex)
            {
                //Insert Error Log
                tUsersErrLog userErrorLog = new tUsersErrLog();

                userErrorLog.ErrTypeID   = (int)ErrorLogging.enumErrorType.Application;
                userErrorLog.ErrSourceID = (int)AuditLogging.enumApplication.SFCBAL;
                userErrorLog.Code        = ex.HResult.ToString();
                userErrorLog.Description = ex.Message;
                userErrorLog.Trace       = ex.StackTrace;

                db.tUsersErrLogs.Add(userErrorLog);
                db.SaveChanges();

                string ErrMsg = "An error occured and we have logged the error. Please try again later.";

                Exception Err = new Exception(ErrMsg, ex);

                return(InternalServerError(Err));
            }
        }