public int AddAttenance(ATTENDANCE_IMPORT ai) { using (var _dbcontext = new PayRollEntities()) { var att = (from aim in _dbcontext.ATTENDANCE_IMPORT where aim.EmployeeId == ai.EmployeeId && aim.AttendanceDate == DbFunctions.TruncateTime(ai.AttendanceDate) select aim).FirstOrDefault(); if (att == null) { _dbcontext.ATTENDANCE_IMPORT.Add(ai); _dbcontext.SaveChanges(); return(ai.Id); } else { return(-2); } } }
public ActionResult AddAttenance(AttenanceModel am) { if (ModelState.IsValid) { ATTENDANCE_IMPORT ai = new ATTENDANCE_IMPORT(); ai.AttendanceLogId = 0; ai.AttendanceDate = Convert.ToDateTime(am.sAttendanceDate); ai.EmployeeId = am.EmployeeId; ai.InTime = DateTime.ParseExact(am.sInTime, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; ai.OutTime = DateTime.ParseExact(am.sOutTime, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; ai.PunchRecords = am.PunchRecords; CommonRepository _repo = new CommonRepository(); _repo.AddAttenance(ai); } else { return(View(am)); } return(RedirectToAction("index")); }