Click here to Skip to main content
15,911,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello

After the comment below I update the Question to clear it out.

What I want to achieve is add a Role to my Employee Object after I Create it

For Example User Creating an Employee by Fulling the form in web application then he decide This Employee(Object) Will now become an Supervisor or Warehouse Op.

in moment when he decide to create a new instance of This object it will inherit all properties and add new in this case the properties i add to the Supervisor Warehouse class

I expect in result get a View what will allow me to pick an Employee Object from the List and a Position (Role) he will be promoted and add it to Database by that it will create an relation between Employee table and for example Position table:

Mr.X

ID

First name
Last Name

...

PositionID
Position Name

and then additional properties what will be added by the property of the new Object what will be created and called Supervisor

at last that how I See that but I can be mistaken and I'm looking for some help

to understand it better also I'm looking for some examples to make sure I can memories them till now most of the tutorials I saw was on Cars Aliens and it's not helping me. That's why I create my own project with a real life concept from my work and I'm trying to learn on hard way by doing mistakes and asking Questions.

I hope i find someone who have some spear time and will explain me that on my own example what i understand

I am confused with that all information and the way to achieve my goal can be easier then I think only involve more Loops

Employee will be just a new object with the properties I add right ?

That's mean by using Supervisor : Employee Supervisor will be also a totally new Object what have all properties of Employee + the properties I include in Supervisor Class Right ??

If I follow That Logic its no point to create Supervisor Object because it will be total new Object Right ?

Then to make it Right I need to create class called Position what will have an ID

and property List<employee> and List<rols>

then create a Supervisor Object and Warehouse op object with all properties and name of Object

as that two object then I can send the ID in int or name in string to List<rols> to make sure my User can choose what Role/Position this employee will have

after that in View I can use razor syntax to state if he choose Supervisor show properties of this object or show properties of Warehouse Op of cores as a text box to full in and add to database then the same in Controller to make sure it will update right tables ????

C#
public class Employee
   {
       [Key]
       public virtual int EmployeeID { get; set; }

       [ForeignKey("TitleID")]
       public virtual Title Title { get; set; }

       [Display(Name = "Title")]
       public virtual int TitleID { get; set; }

    ...

       public byte[] Photo { get; set; }

       [HiddenInput(DisplayValue = true)]
       public string ImageMimeType { get; set; }
   }



C#
public class Position
    {
        [Key]
        public virtual int PositionID { get; set; }

        public virtual string PositionName { get; set; }

        [ForeignKey("EmployeeID")]
        public virtual int EmployeeID { get; set; }
        public virtual Employee Employee { get; set; }

    }

public class WarehouseOp : Employee
    {
        public virtual string PositionName { get; set { value = "Warehouse Op"; } }
        public virtual string RfNr { get; set; }
        public virtual string GrfNr { get; set; }
    }

public class Supervisor : Employee
    {
        public virtual string PositionName { get; set{ value = "Supervisor"; } }
        public virtual string TeamName { get; set; }
        
    }
}  


Best Regards
Posted
Updated 28-Dec-13 13:55pm
v4
Comments
Sergey Alexandrovich Kryukov 28-Dec-13 18:15pm    
I think what you need is not quite the knowledge (even though you might lack some), but more of some skills of modeling the objects and phenomena of real life. Skills are not so easy to pass. Besides, it all depends on what exactly you want to achieve. So far, your problem is not really defined. If your definitions were adequate, they would define what you needs, but as they are concerned, you would need to explain in detail your purpose, relationships between object, concerns, in detail.
—SA
JoCodes 29-Dec-13 3:36am    
The way you have designed the POCO / Models doesnt seem to be correct. http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/implementing-inheritance-with-the-entity-framework-in-an-asp-net-mvc-application which again you might feel like another tutorial but still can get some idea on how to relate the dependent classes as well as restricting over use of inheritance when its not required.
JoCodes 29-Dec-13 3:41am    
Also , instead of trying to ask multiple things separate it or at least a brisk bulleted points will be better to draw even better responses here.
SebSCO 29-Dec-13 5:07am    
Thank You JoCodes The Tuturial help
Now I see how it's work and i saw two ways to sort out my issue.

i could take TPH approach or TPT approach

In TPH approach i just creating models for my Supervisor class and Warehouse Op class they will use them own ID and Tables the problem will be at end when i will creating the Controllers as it will require more Table Join Commands to handle the end app

The TPT approach will allow me to keep all new properties in the same Table and buy implementing the Inheritance it will add to the table a column what will recognize if the fallow employee is a Supervisor or Warehouse Op both approaches have some good and bad sides

I will try to Do both of them and see how they work in live app to see how they look

Thank You

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900