I have very method is equal same
I want have one method do jobs three or more method under
but I try use generic method or reflection but cannot write good method or class my method:
First method
public ActionResult _Create1(MyClassView1 content)
{
if (ModelState.IsValid)
{
MyClass1 Home = new MyClass1();
Mapper.Map(content, Home);
if (content.Id <= 0)
db.MyClasse1s.Add(Home);
else
db.Entry(Home).State = EntityState.Modified;
db.SaveChanges();
return Content("Ok");
}
return PartialView(content);
}
second method
public ActionResult _Create2(MyClassView2 content)
{
if (ModelState.IsValid)
{
MyClass2 Home = new MyClass2();
Mapper.Map(content, Home);
if (content.Id <= 0)
db.MyClasse1s.Add(Home);
else
db.Entry(Home).State = EntityState.Modified;
db.SaveChanges();
return Content("Ok");
}
return PartialView(content);
}
third method
public ActionResult _Create3(MyClassView3 content)
{
if (ModelState.IsValid)
{
MyClass3 Home = new MyClass3();
Mapper.Map(content, Home);
if (content.Id <= 0)
db.MyClasse1s.Add(Home);
else
db.Entry(Home).State = EntityState.Modified;
db.SaveChanges();
return Content("Ok");
}
return PartialView(content);
}
How can merge this class to one class?
thanks for answers