public int CreateWorkSchedule(int employeeId, AttendanceType attCode, DateTime datetime) { try { if (attCode == AttendanceType.ClockIn) { var attendace = new Attendance() { ClockIn = datetime, ClockOut = null, EmployeeId = employeeId }; _attendanceRepository.Add(attendace); } else if (attCode == AttendanceType.ClockOut) { var attendance = _attendanceRepository.GetLastAttendance(employeeId); attendance.ClockOut = datetime; _attendanceRepository.Update(attendance); } _unitOfWork.Commit(); return(0); } catch (Exception ex) { return(-1); } }
public async Task <IActionResult> GymSignIn(string id) { ApplicationUser user = await userManager.FindByIdAsync(id); if (user != null) { // Checking if user is banned. Banned users cannot be signed in to the gym. Claim bannedClaim = (await userManager.GetClaimsAsync(user)) .Where(c => c.Type == "Banned") .FirstOrDefault(); if (bannedClaim == null) { // Sign the user in to the gym by registering the date and time they attended against their id. attendanceRepository.Add(new GymAttendance { Date = DateTime.Now, UserId = user.Id }); return(RedirectToAction(nameof(UserList))); } else { return(RedirectToAction("BannedUser", "Error", new { email = user.Email, name = user.FirstName + " " + user.LastName })); } } else { return(RedirectToAction("UserNotFound", "Error", new { userId = id })); } }
public IHttpActionResult PostAttendance(AttendanceDTO attendanceDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //if (date == null || studentIDList == null || moduleID <= 0) //{ // return BadRequest("One or more parameters are missing values"); //} //Attendance attendance = new Attendance { ModuleID = moduleID, AttendanceDate = date}; Attendance attendance = Mapper.Map <Attendance>(attendanceDTO); AttendanceRepo.Add(attendance); try { AttendanceRepo.Save(); return(Ok(attendance)); } catch { return(BadRequest("Failed to add attendance")); } }
public void AddAttendance(AttendanceModel attendanceModel) { var att = _iAttendanceMapper.Map(attendanceModel); _iAttendanceRepository.Add(att); _iAttendanceRepository.SaveChanges(); }
public async Task <ActionResult <Attendance> > SigninTime(SigninCreateDto signinCreateDto) { try { DateTime localDate = DateTime.UtcNow; string userId = User.Claims.First(c => c.Type == "UserID").Value; var user = await _userManager.FindByIdAsync(userId); var attend = new Attendance() { date = localDate, Pantherid = user.PantherNo, SignInTime = localDate, Notes = signinCreateDto.notes }; _attendanceRepo.Add(attend); await _attendanceRepo.SaveAll(); user.Attendances.Add(attend); await _attendanceRepo.SaveAll(); return(Ok(attend)); } catch (Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.InnerException.Message)); } }
public virtual ActionResult CreateAttendance(CreateAttendanceViewModel viewModel) { var clockIn = Convert.ToDateTime(String.Format("{0} {1}", viewModel.ClockIn.ToShortDateString(), viewModel.ClockInTime)); var clockOut = Convert.ToDateTime(String.Format("{0} {1}", viewModel.ClockOut.ToShortDateString(), viewModel.ClockOutTime)); viewModel.Employees = GetEmployeeNames(); //validate clock in should not be greater than or equal to clock out if (clockIn >= clockOut) { if (viewModel.EmployeeId > 0) { var employee = _employeeRepository.GetById(viewModel.EmployeeId); ViewData["Name"] = employee.FullName; } ModelState.AddModelError("", ErrorMessages.ATTENDANCE_CLOCKIN_GREATER_THAN_CLOCKOUT); return(View("CreateAttendance", viewModel)); } //validate clockin and clockout date, should not be a future date if (clockIn > DateTime.Now || clockOut > DateTime.Now) { if (viewModel.EmployeeId > 0) { var employee = _employeeRepository.GetById(viewModel.EmployeeId); ViewData["Name"] = employee.FullName; } ModelState.AddModelError("", ErrorMessages.ATTENDANCE_INVALID_FUTUREDATE); return(View("CreateAttendance", viewModel)); } var attendance = viewModel.MapItem <Attendance>(); attendance.IsManuallyEdited = true; attendance.ClockIn = clockIn; attendance.ClockOut = clockOut; _attendanceRepository.Add(attendance); _unitOfWork.Commit(); ViewData["CreateSuccess"] = "Attendance successfully created"; return(View(new CreateAttendanceViewModel { Employees = viewModel.Employees })); }
public Attendance Add(AttendanceCreateViewModel Vm) { var entity = _mapper.Map <AttendanceCreateViewModel, Attendance>(Vm); _attendanceRepository.Add(entity); SaveChanges(); return(entity); }
public async Task <IActionResult> PostAttendance([FromBody] Attendance attendance) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _attendanceRepository.Add(attendance); return(CreatedAtAction("GetAttendance", new { id = attendance.Id }, attendance)); }
public IHttpActionResult PutAttendance(Attendance attendance) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } attendance = repository.Add(attendance); return(Content(HttpStatusCode.OK, attendance)); }
public bool SaveAttendance(Attendance attendance) { if (attendance.AttendanceId > 0) { attendance.IsEdited = true; attendanceRepository.Update(attendance); } else { attendanceRepository.Add(attendance); } attendanceRepository.SaveChanges(); return(true); }
public IHttpActionResult PostAttendance(AttendanceDTO AttendanceDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Mapper.Initialize(c => c.CreateMap <AttendanceDTO, Attendance>()); Attendance Attendance = Mapper.Map <Attendance>(AttendanceDTO); attendanceRepo.Add(Attendance); attendanceRepo.Save(); return(CreatedAtRoute("DefaultApi", new { id = Attendance.ID }, Attendance)); }
public void ClockIn(string code) { var employee = _employeeRepository.GetByCode(code); if (employee != null) { var attendance = new Attendance() { EmployeeId = employee.EmployeeId, ClockIn = DateTime.Now, ClockOut = null }; _attendanceRepository.Add(attendance); _unitOfWork.Commit(); } }
public void AddAttendance(AttendanceModel attendance) { var lab = laboratoryRepository.GetById(attendance.Lab.Id); var student = userRepository.GetById(attendance.Student.Id); if (student == null) { throw new Exception("no student with such id"); } if (lab == null) { throw new Exception("no lab wiht such id"); } attendanceRepository.Add(new AttendanceDto { LaboratoryId = lab.Id, UserId = student.Id }); attendanceRepository.Save(); }
public IHttpActionResult CreateAttendance(int id) { var gig = _gigRepository.Get(id); if (gig == null) { return(BadRequest()); } var attendance = new Attendance() { Artist = _userRepository.GetUserCurrent(User.Identity.GetUserId()), Gig = gig }; _attendanceRepository.Add(attendance); _unitOfWork.Complete(); return(Ok(attendance.Id)); }
public async Task <ActionResult <AttendanceModel> > PostAttendanceModel(int labId) { var labModel = await _labRepository.GetById(labId); if (labModel == null) { return(BadRequest()); } var groupModel = await _groupRepository.GetById(labModel.GroupId); if (groupModel == null) { return(BadRequest()); } object result; if (groupModel.Students == null) { return(BadRequest()); } foreach (var studentModel in groupModel.Students) { var model = new AttendanceInputModel { AttendanceId = 0, LabId = labId, StudentId = studentModel.StudentId }; result = await _attendanceRepository.Add(model); if (result.Equals("bad request")) { return(BadRequest()); } } return(NoContent()); }
//public AttendanceService() //{ // attendanceRepository = new AttendanceRepository(); //} public void Add(AttendanceModel attendanceModel) { var newAttendance = mapper.map(attendanceModel); attendanceRepository.Add(newAttendance); }