Using child's property in parent's methods

mother using child as a weapons
using child to hurt other parent
mother using child against father
companies that use child labor 2019
using child as a pawn
using a child as a weapon quotes
ex using child to control me
using a child as a pawn meaning

I have many model classes that I populate with data fetched from web api service. All the classes share many properties like creation date etc.:

public class Car
    {
        public int CarId { get; set; }
        [Browsable(false)]
        public int CreatedBy { get; set; }
        [DisplayName("Utworzył")]
        public string CreatedByName { get; set; }
        [DisplayName("Data utworzenia")]
        public DateTime CreatedOn { get; set; }
        [Browsable(false)]
        public int? LmBy { get; set; }
        [DisplayName("Zmodyfikował")]
        public string LmByName { get; set; }
        [DisplayName("Data modyfikacji")]
        public DateTime? LmOn { get; set; }
        [Browsable(false)]
        public int TenantId { get; set; }
        [Browsable(false)]
        public string TenantName { get; set; }
    }

All the model classes also have methods to create/update related entity in db. For example "Car" class's methods are:

public async Task<bool> Add()
        {
            using (var client = new HttpClient())
            {
                string url = Secrets.ApiAddress + $"CreateCar?token=" + Secrets.TenantToken + "&UserId=" + RuntimeSettings.UserId;
                var serializedProduct = JsonConvert.SerializeObject(this);
                var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
                var result = await client.PostAsync(new Uri(url), content);
                if (result.IsSuccessStatusCode)
                {
                    var rString = await result.Content.ReadAsStringAsync();
                    T _this = JsonConvert.DeserializeObject<T>(rString);
                    this.CarId = _this.CarId;
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        public async void Edit()
        {
            using (var client = new HttpClient())
            {
                string url = Secrets.ApiAddress + $"EditCar?token=" + Secrets.TenantToken + "&id={0}&UserId={1}";
                var serializedProduct = JsonConvert.SerializeObject(this);
                var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
                var result = await client.PutAsync(String.Format(url, this.CarId, RuntimeSettings.UserId), content);
            }
        }

So I thought it'd be good to make 1 model class for all other to derive from. It'd have all the shared properties:

public abstract class Entity<T>
    {
        [Browsable(false)]
        public int CreatedBy { get; set; }
        [DisplayName("Utworzył")]
        public string CreatedByName { get; set; }
        [DisplayName("Data utworzenia")]
        public DateTime CreatedOn { get; set; }
        [Browsable(false)]
        public int? LmBy { get; set; }
        [DisplayName("Zmodyfikował")]
        public string LmByName { get; set; }
        [DisplayName("Data modyfikacji")]
        public DateTime? LmOn { get; set; }
        [Browsable(false)]
        public int TenantId { get; set; }
        [Browsable(false)]
        public string TenantName { get; set; }
    }

It would be used like below:

public class Car : Entity<Car>
    {
        public int CarId { get; set; }
    }

The problem I have is with the methods. If I keep them in parent class (not to create them for each child since 90% of logic is shared), I can't use child's id property (CarId) in the parent's methods simply because such properties don't exist in parent:

public async Task<bool> Add()
        {
            using (var client = new HttpClient())
            {
                string url = Secrets.ApiAddress + $"Create{typeof(T).Name}?token=" + Secrets.TenantToken + "&UserId=" + RuntimeSettings.UserId;
                var serializedProduct = JsonConvert.SerializeObject(this);
                var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
                var result = await client.PostAsync(new Uri(url), content);
                if (result.IsSuccessStatusCode)
                {
                    var rString = await result.Content.ReadAsStringAsync();
                    T _this = JsonConvert.DeserializeObject<T>(rString);
                    this.CarId = _this.CarId; // CarId doesn't exist in parent, it's child's property
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        public async void Edit()
        {
            using (var client = new HttpClient())
            {
                string url = Secrets.ApiAddress + $"Edit{typeof(T).Name}?token=" + Secrets.TenantToken + "&id={0}&UserId={1}";
                var serializedProduct = JsonConvert.SerializeObject(this);
                var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
                var result = await client.PutAsync(String.Format(url, this.CarId, RuntimeSettings.UserId), content); // CarId doesn't exist in parent, it's child's property
            }
        }

Probably If I used more generic ID property names (Id instead of CarId) it would be simpler, but assuming I must stick with the custom names ("CarId","EmployeeId") - what are my choices?

Maybe I could create generic ID property in parent and somehow bind it with child's appropriate id field when I'm inheriting?

The idea of an abstract super-class was absoluetely good. However it doesn´t need to be generic. It should just contain all the common behaviour. Having said this your Entitity-class should also have an abstract ID-property:

public abstract class Entity
{
    [Browsable(false)]
    public int CreatedBy { get; set; }
    [DisplayName("Utworzył")]
    public string CreatedByName { get; set; }
    [DisplayName("Data utworzenia")]
    public DateTime CreatedOn { get; set; }
    [Browsable(false)]
    public int? LmBy { get; set; }
    [DisplayName("Zmodyfikował")]
    public string LmByName { get; set; }
    [DisplayName("Data modyfikacji")]
    public DateTime? LmOn { get; set; }
    [Browsable(false)]
    public int TenantId { get; set; }
    [Browsable(false)]
    public string TenantName { get; set; }
    public abstract int Id { get; set; }
}

Now in your implementing class you can implement the abstract property to return the concrete CarId for example:

public class Car : Entity
{
    public int CarId { get; set; }
    public int Id => CarId;
}

Alternativly you may completely omit the CarId-property from your Car-class and only have the Id from the abstract class:

public class Car : Entity
{
    public int Id get; set; }
}

No matter which of those two approaches you chose your base-class now has an Id-member making your Add-method look like the following:

public async Task<bool> Add()
{
    using (var client = new HttpClient())
    {
        string url = Secrets.ApiAddress + $"Create{this.GetType().Name}?token=" + Secrets.TenantToken + "&UserId=" + RuntimeSettings.UserId;
        var serializedProduct = JsonConvert.SerializeObject(this);
        var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
        var result = await client.PostAsync(new Uri(url), content);
        if (result.IsSuccessStatusCode)
        {
            var rString = await result.Content.ReadAsStringAsync();
            // you don´t need to knoe the actual type, all you need is its Id, so an Entity is just fine
            Entity e = JsonConvert.DeserializeObject(rString);
            this.Id = e.Id; 
            return true;
        }
        else
        {
            return false;
        }
    }
}

List of Goods Produced by Child Labor or Forced Labor, Publication of the List has resulted in new opportunities for ILAB to engage with foreign governments to combat forced labor and child labor. With younger kids, it’s easy to see what they’re doing online. As they get older, it’s not so easy to look over their shoulder. Have open, honest discussions about what sites and type of content are off-limits. Do your research to understand the media your child is using, and check out your child’s browser history to see what sites they visit.

This way:

public abstract class Entity
{
    [Browsable(false)]
    public int CreatedBy { get; set; }
    [DisplayName("Utworzył")]
    public string CreatedByName { get; set; }
    [DisplayName("Data utworzenia")]
    public DateTime CreatedOn { get; set; }
    [Browsable(false)]
    public int? LmBy { get; set; }
    [DisplayName("Zmodyfikował")]
    public string LmByName { get; set; }
    [DisplayName("Data modyfikacji")]
    public DateTime? LmOn { get; set; }
    [Browsable(false)]
    public int TenantId { get; set; }
    [Browsable(false)]
    public string TenantName { get; set; }
}


public class Car : Entity
{
    public int CarId { get; set; }
}

Then, you must override the methods for every different class to handle.

Sign your child in on their Android device, When you use Family Link to manage your child's Google Account, you can Devices running Android 6 or below may need to be set up using the steps for an � These child (or teen) profiles use the Kindle FreeTime feature, which is perhaps the most sophisticated parental-control solution for a tablet operating system Fire OS is actually quite compelling if you’re looking for powerful parental controls and child-friendly features.

You may want to have a look at the repository pattern. In repository pattern, create a base repository with the basic CRUD operations on properties in your Entity abstract class. And then, create derived repository classes for operations on entity specific properties. If you want still want to do in your model classes, you can do as below.

public abstract class Entity<T>
    {
        [Browsable(false)]
        public int CreatedBy { get; set; }
        [DisplayName("Utworzył")]
        public string CreatedByName { get; set; }
        [DisplayName("Data utworzenia")]
        public DateTime CreatedOn { get; set; }
        [Browsable(false)]
        public int? LmBy { get; set; }
        [DisplayName("Zmodyfikował")]
        public string LmByName { get; set; }
        [DisplayName("Data modyfikacji")]
        public DateTime? LmOn { get; set; }
        [Browsable(false)]
        public int TenantId { get; set; }
        [Browsable(false)]
        public string TenantName { get; set; }
        public virtual void Add(){
//operation using base properties
         }

public class Car : Entity<Car>
    {
        public int CarId { get; set; }
        public override void Add(){
            //do custom operation or call base.Add() or whatever you want
        }
    }

}

Use parental controls on your child's iPhone, iPad, and iPod touch , With Content & Privacy Restrictions in Screen Time, you can block or limit specific apps and features on your child's device. And restrict the� Here are five manipulation tactics narcissistic parents use to control their children, even as adults, and some self-care tips for coping: 1) Emotional Blackmail The narcissistic parent appears to

I solved it by implementing small work-around. "Edit" worked already when I put HimBromBeere's suggestion in place. For "Add" to work, I had to changed my Entity class to:

public abstract class Entity<T>
    {
        [Browsable(false)]
        public string AddedItem { get; set; }

        public virtual async Task<bool> Add()
        {
            using (var client = new HttpClient())
            {
                string url = Secrets.ApiAddress + $"Create{typeof(T).Name}?token=" + Secrets.TenantToken + "&UserId=" + RuntimeSettings.UserId;
                var serializedProduct = JsonConvert.SerializeObject(this);
                var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
                var result = await client.PostAsync(new Uri(url), content);
                if (result.IsSuccessStatusCode)
                {
                    var rString = await result.Content.ReadAsStringAsync();
                    AddedItem = rString;
                    return true;
                }
                else
                {
                    MessageBox.Show("Serwer zwrócił błąd przy próbie utworzenia rekordu. Wiadomość: " + result.ReasonPhrase);
                    return false;
                }
            }
        }
    }

And deriving class was changed to:

public class Car : Entity<Car>
    {
        public async override Task<bool> Add()
        {
            bool x = await base.Add();
            if (x)
            {
                try
                {
                    Car _this = JsonConvert.DeserializeObject<Car>(AddedItem);
                    this.CarId = _this.CarId;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                MessageBox.Show("Tworzenie nowego rekordu zakończone powodzeniem!");
                return true;
            }
            else
            {
                return false;
            }
        }
    }

I found HimBromBeere's answer most helpful and so chose his post as answering my question.

Hershey, Nestle and Mars broke their pledges to end child labor in , Cocoa's child laborers. Mars, Nestl� and Hershey pledged nearly two decades ago to stop using cocoa harvested by children. Yet much of the� using a function to get the theme’s version will return the active theme’s version (child if there is a child). the functions named get_stylesheet* look for a child theme first and then the parent. The recommended way of enqueuing the stylesheets is to add a wp_enqueue_scripts action and use wp_enqueue_style() in your child theme’s functions.php.

Ignoring | Consequences | Essentials | Parenting Information, Ignoring usually helps stop behaviors that your child is using to get your attention. This includes behaviors like throwing tantrums, whining, and interrupting. When� Other than using prescription products like Epidiolex, it’s difficult, if not impossible, to control the amount of CBD administered to any child using these products. Other forms of CBD include

How to Use Rewards, You watch your child's behavior and when you catch him doing what you like, you provide a reward. For young children, a chart is often used. Want to help creating� The survey estimates that 123,259 children ages 5 to 17 perform hazardous child labor in El Salvador, including using dangerous tools, carrying heavy loads, working with chemicals, working long or night shifts, and being exposed to dust, smoke, or extreme heat or humidity.

[PDF] Using Child Development Research to Make Appropriate Custody , Using Child Development Research to Make Appropriate Custody and. Access Decisions for Young Children. Family and Conciliation Courts Review; Los� First, make sure that you're using a supported payment method.You can manage and change your payment method from your device or your Apple ID account page.. Then, to comply with child online privacy protection laws, verify your parental consent with your payment method's CVV or security code, or with a verification code sent via SMS.

Comments
  • You need multiple Add() methods. One in the base class that does common code and then one in each inherited class the does unique code. The inherited methods will call the base method to do common code.
  • "So I thought it'd be good to make 1 model class for all other to derive from. It'd have all the shared properties:" Good idea, however you won´t generics for that. A simple abstract super-class is absoluetely sufficient, that contains the common behaviour. The behaviour which is specific to a certain class however should surely be implemented there.
  • Thanks, it put me in the right direction. Unfortunately, there are errors. First, Id is a field in Car class whereas in Entity it's property. I changed it in Car to property too, in a form public override int Id { set => value = CarId; get => CarId; }. Second, I had to remove 'abstract' from Entity class, as with it I couldn't create instance of it with Entity e = JsonConvert.DeserializeObject(rString);. Having done all this, my code compiles and all works fine without "Add". For some reason e.Id=0 after adding, probably there's error in the Id property I created for Car class
  • tested it a little more and I think I understand. What gets back from Json deserialization is of type Entity (also tried Entity<Car> with same result) which by design does not have CarId property. As the object fetched from web api doesn't have "Id" property (but DOES have "CarId"), deserializer can't deserialize it properly... I'm afraid this can't be fixed
  • Thanks Marco, but honestly speaking I was looking for more generic solution (so I don't have to override the methods). With overriding it'd be simple but I want to keep as much code as possible in parent. Of course I don't know if it can be done so there's a chance your solution is the best
  • There isn't a way, if you don't want to write more than 1 method, you can check "this" 's type and cast the object and add an if for every object but if you must do this, at this point it's better to override.