コード例 #1
0
        public void PostUpdateUser([FromBody] CreateUser userBeingUpdated)
        {
            int userid = 0;

            if (Auth.IsAuthenticated())
            {
                userid = Auth.GetUserId();
            }

            // If an edit is happening to a brand-new user, it is possible that the UI does not yet
            // know its UserId. In that case we will attempt to determine it via the primary email.
            using (CSET_Context context = new CSET_Context())
            {
                if (userBeingUpdated.UserId == 0 || userBeingUpdated.UserId == 1)
                {
                    var u = context.USERS.Where(x => x.PrimaryEmail == userBeingUpdated.saveEmail).FirstOrDefault();
                    if (u != null)
                    {
                        userBeingUpdated.UserId = u.UserId;
                    }
                }
            }

            int assessmentId = -1;

            try
            {
                assessmentId = Auth.AssessmentForUser();
            }
            catch (HttpResponseException)
            {
                // The user is not currently 'in' an assessment
            }

            if (userid != userBeingUpdated.UserId)
            {
                if (assessmentId >= 0)
                {
                    // Updating a Contact in the context of the current Assessment.
                    Auth.AuthorizeAdminRole();

                    ContactsManager cm = new ContactsManager();
                    cm.UpdateContact(new ContactDetail
                    {
                        AssessmentId     = assessmentId,
                        AssessmentRoleId = userBeingUpdated.AssessmentRoleId,
                        FirstName        = userBeingUpdated.FirstName,
                        LastName         = userBeingUpdated.LastName,
                        PrimaryEmail     = userBeingUpdated.PrimaryEmail,
                        UserId           = userBeingUpdated.UserId,
                        Title            = userBeingUpdated.Title,
                        Phone            = userBeingUpdated.Phone
                    });
                    BusinessLogic.Helpers.AssessmentUtil.TouchAssessment(assessmentId);
                }
            }
            else
            {
                // Updating myself
                using (CSET_Context context = new CSET_Context())
                {
                    // update user detail
                    var user = context.USERS.Where(x => x.UserId == userBeingUpdated.UserId).FirstOrDefault();
                    user.FirstName    = userBeingUpdated.FirstName;
                    user.LastName     = userBeingUpdated.LastName;
                    user.PrimaryEmail = userBeingUpdated.PrimaryEmail;


                    // update my email address on any ASSESSMENT_CONTACTS
                    var myACs = context.ASSESSMENT_CONTACTS.Where(x => x.UserId == userBeingUpdated.UserId).ToList();
                    foreach (var ac in myACs)
                    {
                        ac.PrimaryEmail = userBeingUpdated.PrimaryEmail;
                    }

                    context.SaveChanges();


                    // update security questions/answers
                    var sq = context.USER_SECURITY_QUESTIONS.Where(x => x.UserId == userid).FirstOrDefault();
                    if (sq == null)
                    {
                        sq = new USER_SECURITY_QUESTIONS
                        {
                            UserId = userid
                        };
                        context.USER_SECURITY_QUESTIONS.Attach(sq);
                        context.SaveChanges();
                    }
                    sq.SecurityQuestion1 = NullIfEmpty(userBeingUpdated.SecurityQuestion1);
                    sq.SecurityAnswer1   = NullIfEmpty(userBeingUpdated.SecurityAnswer1);
                    sq.SecurityQuestion2 = NullIfEmpty(userBeingUpdated.SecurityQuestion2);
                    sq.SecurityAnswer2   = NullIfEmpty(userBeingUpdated.SecurityAnswer2);

                    // don't store a question or answer without its partner
                    if (sq.SecurityQuestion1 == null || sq.SecurityAnswer1 == null)
                    {
                        sq.SecurityQuestion1 = null;
                        sq.SecurityAnswer1   = null;
                    }
                    if (sq.SecurityQuestion2 == null || sq.SecurityAnswer2 == null)
                    {
                        sq.SecurityQuestion2 = null;
                        sq.SecurityAnswer2   = null;
                    }

                    // delete or add/update the record
                    if (sq.SecurityQuestion1 != null || sq.SecurityQuestion2 != null)
                    {
                        context.USER_SECURITY_QUESTIONS.AddOrUpdate(sq, x => x.UserId);
                    }
                    else
                    {
                        // both questions are null -- remove the record
                        context.USER_SECURITY_QUESTIONS.Remove(sq);
                    }

                    try
                    {
                        context.SaveChanges();
                        // Only touch the assessment if the user is currently in one.
                        if (assessmentId >= 0)
                        {
                            BusinessLogic.Helpers.AssessmentUtil.TouchAssessment(assessmentId);
                        }
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        // this can happen if there is no USER_SECURITY_QUESTIONS record
                        // but the code tries to delete it.
                    }
                }
            }
        }
コード例 #2
0
        public ContactsListResponse RemoveContactFromAssessment([FromBody] ContactRemoveParameters contactRemove)
        {
            if (contactRemove == null)
            {
                var err = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content      = new StringContent("The input parameters are not valid"),
                    ReasonPhrase = "The input parameters are not valid"
                };
                throw new HttpResponseException(err);
            }

            int currentUserId = Auth.GetUserId();

            ASSESSMENT_CONTACTS ac = null;

            using (var db = new CSET_Context())
            {
                // explicit removal using the ID of the connection
                if (contactRemove.AssessmentContactId > 0)
                {
                    ac = db.ASSESSMENT_CONTACTS.Where(x => x.Assessment_Contact_Id == contactRemove.AssessmentContactId).FirstOrDefault();
                }

                // implied removal of the current user's connection to the assessment
                if (contactRemove.AssessmentId > 0)
                {
                    ac = db.ASSESSMENT_CONTACTS.Where(x => x.Assessment_Id == contactRemove.AssessmentId && x.UserId == currentUserId).FirstOrDefault();
                }
            }

            if (ac == null)
            {
                var err = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content      = new StringContent("The input parameters are not valid"),
                    ReasonPhrase = "The input parameters are not valid"
                };
                throw new HttpResponseException(err);
            }


            // Determine the current user's role.
            ContactsManager cm = new ContactsManager();
            int             currentUserRole = cm.GetUserRoleOnAssessment(TransactionSecurity.CurrentUserId, ac.Assessment_Id) ?? 0;

            // If they are a USER and are trying to remove anyone but themself, forbid it
            if (currentUserRole == (int)ContactsManager.ContactRole.RoleUser && ac.UserId != currentUserId)
            {
                var err = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content      = new StringContent("The current user does not have administrative authority for the Assessment."),
                    ReasonPhrase = "The only contact that a user role can remove is themself."
                };
                throw new HttpResponseException(err);
            }

            // Do not allow the user to remove themself if they are the last Admin on the assessment and there are other users
            if (ac.UserId == currentUserId &&
                Auth.AmILastAdminWithUsers(ac.Assessment_Id))
            {
                var err = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content      = new StringContent("The current user is the only Administrator contact on the Assessment"),
                    ReasonPhrase = "An Assessment must have at least one Administrator contact."
                };
                throw new HttpResponseException(err);
            }

            List <ContactDetail> newList;

            try
            {
                newList = cm.RemoveContact(ac.Assessment_Contact_Id);
            }
            catch (NoSuchUserException)
            {
                // This could happen if they try to remove a contact that wasn't on the assessment.
                // It's not critical.

                //Are we sure this is the ONLY CASE that could ever happen?
                //changing it to catch specific instance just in case there could be
                //anything else that could ever happen
            }

            ContactsManager      contactManager = new ContactsManager();
            ContactsListResponse resp           = new ContactsListResponse
            {
                ContactList     = contactManager.GetContacts(ac.Assessment_Id),
                CurrentUserRole = contactManager.GetUserRoleOnAssessment(TransactionSecurity.CurrentUserId, ac.Assessment_Id) ?? 0
            };

            return(resp);
        }
コード例 #3
0
        public object GetAllRoles()
        {
            ContactsManager cm = new ContactsManager();

            return(cm.GetAllRoles());
        }
コード例 #4
0
ファイル: FormMainInit.cs プロジェクト: wmlabtx/abclient
        private void RestoreElements()
        {
            ChangeAutoboiState(AppVars.Profile.LezDoAutoboi ? AutoboiState.AutoboiOn : AutoboiState.AutoboiOff);

            AppVars.AutoRefresh       = false;
            buttonAutoRefresh.Checked = false;

            buttonAutoAnswer.Checked = AppVars.Profile.DoAutoAnswer;
            tsBossTrace.Checked      = false;

            buttonDoTexLog.Checked        = AppVars.Profile.DoTexLog;
            buttonShowPerformance.Checked = AppVars.Profile.ShowPerformance;
            buttonAutoFish.Checked        = AppVars.Profile.FishAuto;
            if (AppVars.Profile.FishAuto)
            {
                AppVars.SwitchToPerc  = true;
                AppVars.SwitchToFlora = true;
            }

            buttonAutoSkin.Checked = AppVars.Profile.SkinAuto;
            if (AppVars.Profile.SkinAuto)
            {
                AppVars.SwitchToPerc       = true;
                AppVars.SwitchToFlora      = true;
                AppVars.AutoSkinCheckUm    = true;
                AppVars.AutoSkinCheckRes   = true;
                AppVars.SkinUm             = 0;
                AppVars.AutoSkinCheckKnife = true;
                AppVars.AutoSkinArmedKnife = false;
            }

            buttonSilence.Checked      = !AppVars.Profile.Sound.Enabled;
            statuslabelTorgAdv.Enabled = AppVars.Profile.TorgActive;
            if (AppVars.Profile.SelectedRightPanel < tabControlRight.TabCount)
            {
                tabControlRight.SelectedIndex = AppVars.Profile.SelectedRightPanel;
            }

            menuitemGuamod.Checked = AppVars.Profile.DoGuamod;

            UpdateStat();

            panelRight.Width = AppVars.Profile.Splitter.Width;
            if (AppVars.Profile.Splitter.Collapsed)
            {
                collapsibleSplitter.ToggleState();
            }

            LoadTabs();
            UpdateLocationSafe(AppVars.Profile.MapLocation);

            AppVars.Tied     = 0;
            AppVars.LastTied = DateTime.MinValue;

            AppVars.LastChList = DateTime.Now;

            tsContactTrace.Checked = AppVars.Profile.DoContactTrace;
            tsBossTrace.Checked    = AppVars.Profile.DoBossTrace;

            ContactsManager.Init(treeContacts);
            RoomManager.StartTracing();

            Things.ThingsDb.Load();

            AppVars.LastAdv     = DateTime.Now;
            AppVars.LastTorgAdv = DateTime.Now;
        }
コード例 #5
0
 internal void UpdateContact(Contact ce)
 {
     ContactsManager.Update(treeContacts, ce);
 }
コード例 #6
0
 // PUT api/<controller>/5
 /// <summary>
 /// Puts the specified identifier.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 /// <exception cref="HttpResponseException"></exception>
 public Contacts Put(string id, [FromBody] Contacts value)
 {
     return(ContactsManager.UpdateItem(value));
 }
コード例 #7
0
 // DELETE api/<controller>/5
 /// <summary>
 /// Deletes the specified identifier.
 /// </summary>
 /// <param name="id">The identifier.</param>
 public void Delete(Int32 id)
 {
     ContactsManager.DeleteItem(id);
 }
コード例 #8
0
 // POST api/<controller>
 /// <summary>
 /// Posts the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public Contacts Post([FromBody] Contacts value)
 {
     return(ContactsManager.AddItem(value));
 }
コード例 #9
0
 // GET api/<controller>/5
 /// <summary>
 /// Gets the specified COM group identifier.
 /// </summary>
 /// <param name="ContactsId">The COM group identifier.</param>
 /// <returns></returns>
 public Contacts Get(Int32 Id)
 {
     return(ContactsManager.GetItemByID(Id));
 }
コード例 #10
0
 public ContactsCollection GetbyUser(string usr)
 {
     return(ContactsManager.GetbyUser(usr));
 }
コード例 #11
0
 // GET api/<controller>
 /// <summary>
 /// Gets this instance.
 /// </summary>
 /// <returns></returns>
 public ContactsCollection Get()
 {
     return(ContactsManager.GetAllItem());
 }
コード例 #12
0
 public ContactsController(ContactsManager manager)
 {
     this.manager = manager;
 }