locked
how can only the creator of the entity can modify some properties of the entity RRS feed

  • Question

  • hi, i am a ls newbie

    i have a list and detail screen.

    i want  a few properties of the entity  can only be modified by the creator of the entity, not by the others.

    this is my code

     partial void IsClosed_Validate(EntityValidationResultsBuilder results)
            {
                string currentUser = Application.User.Name;
                if (currentUser != null)
                {
                    Staff currentStaff = DataWorkspace.ApplicationData.Staffs.Where(staff => staff.LoginName == currentUser).FirstOrDefault();
                    if (currentStaff != null)
                    {
                        if (currentStaff.Name != this.CreatedByWhichStaff.Name)
                            results.AddEntityError("ccccccccccccccccc");
                    }
                }
    
    
                }
    

    but the above code will execute everytime a person modiy this entity, no matter which property he modified. i only want the above code to excute when the isclosed property is modified

    thank you.

    sorry,the shift key of my keyborad is not working well.


    • Edited by wanghu Friday, January 31, 2014 2:46 PM added something
    Friday, January 31, 2014 2:41 PM

Answers

  • I think I would approach this differently. Rather than waiting until you validate the control to check to see if the user is able to change the state of the control I think I would just disable the control if they aren't allowed to.

    Therefore on the screen, select the screen entity then click the arrow next to write code and chose YourEntity_Changed.

    I would then use something like this:

    partial void YourEntity_Changed(NotifyCollectionChangedEventArgs e)
            {
                if (Application.User.Name != YourEntitiy.SelectedItem.CreatedBy)
                {
                    this.FindControl("YourControlName").IsEnabled = false;
                }
            }

    This will stop the user even being able to change the state of the control if they aren't allowed to. You may need to do some checking to see whether it's a new record or not but that should get you going.

    HTH!

    Paul.

    • Proposed as answer by Paul Pitchford Saturday, February 1, 2014 10:44 PM
    • Marked as answer by Angie Xu Sunday, February 9, 2014 9:31 AM
    Friday, January 31, 2014 4:15 PM
  • Thank You,Paul!

    Put your code in Entity_SelectionChanged() ,and it works.

     string currentUser = Application.User.Name;                if (currentUser != null)                {                    Staff currentStaff = DataWorkspace.ApplicationData.Staffs.Where(staff => staff.LoginName == currentUser).FirstOrDefault();                    if (currentStaff != null)                    {                        if (currentStaff.Name != this.Issues.SelectedItem.CreatedByWhichStaff.Name)                        {                            this.FindControl("Subject1").IsEnabled = false;                        }                        else                        {                            this.FindControl("Subject1").IsEnabled = true;                        }                    }                }

    • Marked as answer by wanghu Saturday, February 1, 2014 4:13 AM
    Saturday, February 1, 2014 4:10 AM

All replies

  • I think I would approach this differently. Rather than waiting until you validate the control to check to see if the user is able to change the state of the control I think I would just disable the control if they aren't allowed to.

    Therefore on the screen, select the screen entity then click the arrow next to write code and chose YourEntity_Changed.

    I would then use something like this:

    partial void YourEntity_Changed(NotifyCollectionChangedEventArgs e)
            {
                if (Application.User.Name != YourEntitiy.SelectedItem.CreatedBy)
                {
                    this.FindControl("YourControlName").IsEnabled = false;
                }
            }

    This will stop the user even being able to change the state of the control if they aren't allowed to. You may need to do some checking to see whether it's a new record or not but that should get you going.

    HTH!

    Paul.

    • Proposed as answer by Paul Pitchford Saturday, February 1, 2014 10:44 PM
    • Marked as answer by Angie Xu Sunday, February 9, 2014 9:31 AM
    Friday, January 31, 2014 4:15 PM
  • Thank You,Paul!

    Put your code in Entity_SelectionChanged() ,and it works.

     string currentUser = Application.User.Name;                if (currentUser != null)                {                    Staff currentStaff = DataWorkspace.ApplicationData.Staffs.Where(staff => staff.LoginName == currentUser).FirstOrDefault();                    if (currentStaff != null)                    {                        if (currentStaff.Name != this.Issues.SelectedItem.CreatedByWhichStaff.Name)                        {                            this.FindControl("Subject1").IsEnabled = false;                        }                        else                        {                            this.FindControl("Subject1").IsEnabled = true;                        }                    }                }

    • Marked as answer by wanghu Saturday, February 1, 2014 4:13 AM
    Saturday, February 1, 2014 4:10 AM