1.Yes I have added The Edmx file It showing me two tables that are connected by empId
2.using CheckInCheckOut.Models;I have Added It my Home controller class.
3.I have Created the object EmployeeContext EmpDB = new EmployeeContext();
Then I have Created the Object of my EmployeeContext class and in my EmployeeContext following is the code.
public int empId { get; set; }
public string empName { get; set; }
public string designation { get; set; }
public DateTime checkIn { get; set; }
public DateTime checkOut { get; set; }
public DbSet<Employee> Employees { get; set; }
public DbSet<Job> Jobs { get; set; }
Then Employee class
public int EmpId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<Employee> Employees { get; set; }
And I have two tables of Employee and CheckInCheckOut in which empId Is connected by relation.
Then I have EmployeeController Class
public ActionResult Index()
{
var names = new List<Employee>
{
new Employee{Name="Azhar ul Haq"},
new Employee{Name="Saqib jillani"},
new Employee{Name="Wisal Ahmad"},
new Employee{Name="Akhtar sb"},
new Employee{Name="M Ali Qadar"},
new Employee{Name="Miss Sadaf"}
};
return View(names);
}
public string Employee()
{
return "This Application Going to tell you the employees checkin out Time";
}
public ActionResult Details(int id)
{
var job = new Job { JobTitle = "jobId" + id };
return View(job);
}
public ActionResult Browse(string Name)
{
var EmpName=new Employee{Name=Name};
return View(EmpName);
And I am writing My code that you guide me in the Home controller as the My pic is in the HomePage and I have added the pic In the index view of the homecontroller.So I am not accessing the feilds of data.
Kindly Tell Me where I am going wrong.
Progress Is simple that I Have Added links to employee Name and employee pic when I click on the image I go to page Home/Begin/
Which is just A blank Page as a skeleton I made it.I would be thank full to you As you are guiding me .
Here, employee is the table of my database. You have to take your database table name and insert the current date after clicking on the image/Action Link.
You might have listed the all employees in table using for loop.
So here {id=.....} is input from view to controller
Here your primary id of table comes like item.columnname
Then in code behind you can access the value of your employee id, as per i have mentioned earliar.
If it doesnt help you then post your code from both .aspx page and controller page.
Thanks,
Rahul Dhamale.
Please, Mark as Answer if this post helps you....!!!
I have donE a lot of work but Now I am getting an Exception Would you Please guide me for this.
I have Updated the code,In which I am getting current date time when I click on the "Create New" it fills the field of CheckInTime Automatically and when I click on edit It fills the Checkout field for me but when I click on the save button It arose
an Exception"Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries."what should I do to handle the Exception.Kindly Reply. Thank you.The codes where I am getting exception in saving the db is given Below.
public ActionResult Create()
{
EmployeeContext empDB = new EmployeeContext();
Employee emp = new Employee();
var emp1 = new Employee()
{
CheckInTime = DateTime.Now
};
empDB.SaveChanges();
return View(emp1);
}
public ActionResult Edit(int id) {
Employee employee = db.Employees.Find(id);
if (employee.CheckOutTime == null) { var emp2 = new Employee(); { emp2.CheckOutTime = DateTime.Now; }; return View(emp2); }
return View(employee.CheckOutTime); }
// // POST: /Employee/Edit/5
[HttpPost] public ActionResult Edit(Employee employee) { Employee em = new Employee();
qqaadir
Member
96 Points
150 Posts
Re: MVC 3 Tutorial Movies database
Feb 24, 2012 12:47 PM|LINK
Please guide Me That How could I link my Db to My pic On click event it Add entry in the time In Column.
qqaadir
Member
96 Points
150 Posts
Re: MVC 3 Tutorial Movies database
Feb 24, 2012 01:12 PM|LINK
What is DOJ Here? I understand you have created the object of context class and then employee class After That what is the DOJ?
I just Added The Data in the model It looks I am going on right track.
Thank you
Rahul Dhamal...
Member
65 Points
57 Posts
Re: MVC 3 Tutorial Movies database
Feb 24, 2012 01:22 PM|LINK
Hi,
1) Have you added the .dbml or .edmx file and drag all your database tables.
2) if yes then add the reference of application models in your controller class.
3) Create the object of datacontext of your database. e.g. TMS_DBDataContext context= new TMS_DBDataContext();
4) and then you can access your table like context .<yourtableName>
If this is not satisfy your requirement then please elaborate your requirements and your current progress.
DOJ is the column name of a sample table.
For reference purpose see the following example:
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
qqaadir
Member
96 Points
150 Posts
Re: MVC 3 Tutorial Movies database
Feb 24, 2012 01:56 PM|LINK
1.Yes I have added The Edmx file It showing me two tables that are connected by empId
2.using CheckInCheckOut.Models;I have Added It my Home controller class.
3.I have Created the object EmployeeContext EmpDB = new EmployeeContext();
Then I have Created the Object of my EmployeeContext class and in my EmployeeContext following is the code.
public int empId { get; set; }
public string empName { get; set; }
public string designation { get; set; }
public DateTime checkIn { get; set; }
public DateTime checkOut { get; set; }
public DbSet<Employee> Employees { get; set; }
public DbSet<Job> Jobs { get; set; }
Then Employee class
public int EmpId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<Employee> Employees { get; set; }
And I have two tables of Employee and CheckInCheckOut in which empId Is connected by relation.
Then I have EmployeeController Class
public ActionResult Index()
{
var names = new List<Employee>
{
new Employee{Name="Azhar ul Haq"},
new Employee{Name="Saqib jillani"},
new Employee{Name="Wisal Ahmad"},
new Employee{Name="Akhtar sb"},
new Employee{Name="M Ali Qadar"},
new Employee{Name="Miss Sadaf"}
};
return View(names);
}
public string Employee()
{
return "This Application Going to tell you the employees checkin out Time";
}
public ActionResult Details(int id)
{
var job = new Job { JobTitle = "jobId" + id };
return View(job);
}
public ActionResult Browse(string Name)
{
var EmpName=new Employee{Name=Name};
return View(EmpName);
And I am writing My code that you guide me in the Home controller as the My pic is in the HomePage and I have added the pic In the index view of the homecontroller.So I am not accessing the feilds of data.
Kindly Tell Me where I am going wrong.
Progress Is simple that I Have Added links to employee Name and employee pic when I click on the image I go to page Home/Begin/
Which is just A blank Page as a skeleton I made it.I would be thank full to you As you are guiding me .
thank You.
Rahul Dhamal...
Member
65 Points
57 Posts
Re: MVC 3 Tutorial Movies database
Feb 24, 2012 02:27 PM|LINK
Hi,
So you have to access the fields in controller page. like employee id, on which we have clicked.
So you can do by following way :
1) <%: Html.ActionLink("TimeIN", "Browse", new { id = item.TMS_EMPLOYEE_ID })%>
and in function you can access the employee_id :
public ActionResult Browse(int? id)
{ ..... }
2) Another way is after clicking on image link follow the following url
http://kitsula.com/Article/Html.ImageActionLink-extension
3) And also by using following link with css
<%= Html.ActionLink("TimeIN", "Browse", new { id = item.TMS_EMPLOYEE_ID }, new { @class="classname" }) %> a.classname { background: url(../Images/image.gif) no-repeat top left; display: block; width: 150px; height: 150px; text-indent: -9999px; /* hides the link text */ }qqaadir
Member
96 Points
150 Posts
Re: MVC 3 Tutorial Movies database
Feb 24, 2012 04:43 PM|LINK
I have seen the link and the code previously you posted.could you see my contextclass and employee class
So please tell me one thing sir as you created object of contextclass and then an object of employee class and then you then you
added system datetime using Employee class object Am I right ?
OK if I seen in my side I can Only include that db with my Context class Object and that is wrong I think because it doesn't work
So Please guide me more I have Added the lilnes you told me but Employee class object cannot find table attributes.
Please see my code and tell me whats wrong there?
Thank You
qqaadir
Member
96 Points
150 Posts
Re: MVC 3 Tutorial Movies database
Feb 24, 2012 05:20 PM|LINK
Please elaborate me about the action link from new{id=what should be here} thank you.
qqaadir
Member
96 Points
150 Posts
Re: MVC 3 Tutorial Movies database
Feb 24, 2012 05:20 PM|LINK
Please elaborate me about the action link from new{id=what should be here} thank you.
Rahul Dhamal...
Member
65 Points
57 Posts
Re: MVC 3 Tutorial Movies database
Feb 27, 2012 06:48 AM|LINK
Hi,
Here, employee is the table of my database. You have to take your database table name and insert the current date after clicking on the image/Action Link.
You might have listed the all employees in table using for loop.
So here {id=.....} is input from view to controller
Here your primary id of table comes like item.columnname
Then in code behind you can access the value of your employee id, as per i have mentioned earliar.
If it doesnt help you then post your code from both .aspx page and controller page.
Thanks,
Rahul Dhamale.
qqaadir
Member
96 Points
150 Posts
Re: MVC 3 Tutorial Movies database
Feb 27, 2012 01:28 PM|LINK
Dear Rahul,
I have donE a lot of work but Now I am getting an Exception Would you Please guide me for this.
I have Updated the code,In which I am getting current date time when I click on the "Create New" it fills the field of CheckInTime Automatically and when I click on edit It fills the Checkout field for me but when I click on the save button It arose an Exception"Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries."what should I do to handle the Exception.Kindly Reply.
Thank you.The codes where I am getting exception in saving the db is given Below.
public ActionResult Create(){EmployeeContext empDB = new EmployeeContext();Employee emp = new Employee();{return View(emp1);public ActionResult Edit(int id)
{
Employee employee = db.Employees.Find(id);
if (employee.CheckOutTime == null)
{
var emp2 = new Employee();
{
emp2.CheckOutTime = DateTime.Now;
};
return View(emp2);
}
return View(employee.CheckOutTime);
}
//
// POST: /Employee/Edit/5
[HttpPost]
public ActionResult Edit(Employee employee)
{
Employee em = new Employee();
if (ModelState.IsValid)
{
//db.Entry(employee).State = EntityState.Modified;
db.Entry(employee).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(employee.CheckOutTime=System.DateTime.Today);
}
//
// GET: /Employee/Delete/5
public ActionResult Delete(int id)
{
Employee employee = db.Employees.Find(id);
return View(employee);
}