예제 #1
0
        public ActionResult CheckOut(tblTimeSheet timesheet)
        {
            try
            {

                if (timesheet.TextBox1 == null || timesheet.TextBox1.Trim().Length == 0)
                    ModelState.AddModelError("TextBox1", "Description of Work is required.");

                if (ModelState.IsValid)
                {
                    db.Entry(timesheet).State = EntityState.Modified;
                    timesheet.OutTime = System.DateTime.Now;
                    tblEmployee tblemployee = db.tblEmployees.Find(timesheet.EmpID);
                    tblemployee.InOffice = false;
                    db.SaveChanges();

                    return RedirectToAction("Index");
                }
                else {
                    timesheet.tblEmployee = db.tblEmployees.Find(timesheet.EmpID);
                    return View(timesheet);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                return RedirectToAction("Index");
            }
        }
예제 #2
0
        public ActionResult CheckIn(Guid id)
        {
            try
            {
                tblTimeSheet timesheet = new tblTimeSheet();
                timesheet.ID = Guid.NewGuid();
                timesheet.EmpID = id;
                timesheet.InTime = System.DateTime.Now;
                db.tblTimeSheets.Add(timesheet);

                tblEmployee tblemployee = db.tblEmployees.Find(id);
                tblemployee.InOffice = true;
                db.SaveChanges();

                return RedirectToAction("Index");

            }
            catch (DbEntityValidationException ex)
            {
                Console.WriteLine(ex.EntityValidationErrors);
                return RedirectToAction("Index");
            }
        }