public async Task <IActionResult> Edit(int id, [Bind("AttendanceID,Name,Attendance_Date,Attendance_status")] Attendance attendance) { if (id != attendance.AttendanceID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(attendance); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AttendanceExists(attendance.AttendanceID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(attendance)); }
public async Task <User> Remove(int id) { var user = await _context.User.SingleAsync(a => a.Id == id); _context.User.Remove(user); await _context.SaveChangesAsync(); return(user); }
public async Task <Student> Remove(int id) { var student = await _context.Student.SingleAsync(a => a.Id == id); _context.Student.Remove(student); await _context.SaveChangesAsync(); return(student); }
public async Task <Attendance> Remove(int id) { var attendance = await _context.Attendance.SingleAsync(a => a.Id == id); _context.Attendance.Remove(attendance); await _context.SaveChangesAsync(); return(attendance); }
public async Task <Teacher> Remove(int id) { var teacher = await _context.Teacher.SingleAsync(a => a.Id == id); _context.Teacher.Remove(teacher); await _context.SaveChangesAsync(); return(teacher); }
public async Task <IActionResult> Create([Bind("ID,Name,DOB,UnivId")] Users users) { if (ModelState.IsValid) { _context.Add(users); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(users)); }
//Mark registration for today public async Task RegistrationForToday(string userId) { var user = await _context.Employees.FirstAsync(e => e.UserId == userId); //Check if it is weekend if (IsWeekend()) { //Check the attendance closing time var settings = await _context.Settings.FirstAsync(); if (DateTime.Now < settings.AttendanceTime) { //Check if there is an existing record for the day var anyAttendance = await _context.Attendances.AnyAsync(e => e.EmployeeId == user.EmployeeId && e.AttendanceTime.ToShortDateString() == DateTime.Today.ToShortDateString()); if (!anyAttendance) { //record attendance var newAtten = new Attendance { EmployeeId = user.EmployeeId, AttendanceTime = DateTime.UtcNow }; _context.Attendances.Add(newAtten); await _context.SaveChangesAsync(); } } } }
public async Task <string> UploadAttendanceToRemote() { var remoteAttendanceIds = _remoteContext.Attendances.Select(x => x.Id).ToHashSet(); var localAttendancesNotInRemote = _localContext.Attendances.Where(x => !remoteAttendanceIds.Contains(x.Id)).AsNoTracking().ToList(); if (localAttendancesNotInRemote.Count < 1) { return(""); } await _remoteContext.Attendances.AddRangeAsync(localAttendancesNotInRemote); var i = await _remoteContext.SaveChangesAsync(); return(i > 0 ? "" : "Uploading local attendance record failed. Report cannot be generated"); }
public async Task <IActionResult> Register([FromBody] RegisterDto model) { if (!ModelState.IsValid) { return(BadRequest("Fill in the necessary fields")); } var user = new AppUser { UserName = model.Email, Email = model.Email, Fullname = model.Name }; var result = await _userManager.CreateAsync(user, model.Password); await _userManager.AddToRoleAsync(user, "Admin"); if (result.Succeeded) { //Create employee record var newEmpy = new Employee { Fullname = model.Name, UserId = user.Id }; _context.Employees.Add(newEmpy); await _context.SaveChangesAsync(); return(Ok("Account Created successfully")); } return(BadRequest("Username already exists")); }
public async Task <string> SyncAllData() { try { var remoteDept = _remoteContext.Departments.ToList(); var remoteLevels = _remoteContext.Levels.ToList(); var remoteStaffCourse = _remoteContext.StaffCourses.ToList(); var remoteCourse = _remoteContext.Courses.ToList(); var remoteTitle = _remoteContext.Titles.ToList(); var remoteSemester = _remoteContext.SessionSemesters.ToList(); var remoteStaff = _remoteContext.Staff.ToList(); var remoteStudent = _remoteContext.Students.ToList(); var remoteCourseReg = _remoteContext.CourseRegistrations.ToList(); var remoteStudentFingers = _remoteContext.StudentFingers.ToList(); var remoteStaffFingers = _remoteContext.StaffFingers.ToList(); var remoteSetting = _remoteContext.SystemSettings.First(); var remoteAppSetting = _remoteContext.AppSettings.First(); //sqlite doesn't support truncate statement _localContext.Database.ExecuteSqlRaw("DELETE FROM Course"); _localContext.Database.ExecuteSqlRaw("DELETE FROM CourseRegistration"); _localContext.Database.ExecuteSqlRaw("DELETE FROM Department"); _localContext.Database.ExecuteSqlRaw("DELETE FROM PersonTitle"); _localContext.Database.ExecuteSqlRaw("DELETE FROM SessionSemester"); _localContext.Database.ExecuteSqlRaw("DELETE FROM StaffCourse"); _localContext.Database.ExecuteSqlRaw("DELETE FROM User"); _localContext.Database.ExecuteSqlRaw("DELETE FROM StudentDetail"); _localContext.Database.ExecuteSqlRaw("DELETE FROM StudentLevel"); _localContext.Database.ExecuteSqlRaw("DELETE FROM StudentFinger"); _localContext.Database.ExecuteSqlRaw("DELETE FROM StaffFingerprint"); _localContext.Database.ExecuteSqlRaw("DELETE FROM SystemSettings"); _localContext.Database.ExecuteSqlRaw("DELETE FROM AppSettings"); _localContext.Courses.AddRange(remoteCourse); _localContext.CourseRegistrations.AddRange(remoteCourseReg); _localContext.Departments.AddRange(remoteDept); _localContext.Titles.AddRange(remoteTitle); _localContext.SessionSemesters.AddRange(remoteSemester); _localContext.StaffCourses.AddRange(remoteStaffCourse); _localContext.Staff.AddRange(remoteStaff); _localContext.Students.AddRange(remoteStudent); _localContext.Levels.AddRange(remoteLevels); _localContext.StudentFingers.AddRange(remoteStudentFingers); _localContext.StaffFingers.AddRange(remoteStaffFingers); _localContext.SystemSettings.Add(remoteSetting); _localContext.AppSettings.Add(remoteAppSetting); //var remoteAttendanceIds = _remoteContext.Attendances.Select(x => x.Id).ToHashSet(); //var toUpload = _localContext.Attendances.Where(x => !remoteAttendanceIds.Contains(x.Id)).AsNoTracking().ToList(); var localAttendanceIds = _localContext.Attendances.Select(x => x.Id).ToHashSet(); var toDownload = _remoteContext.Attendances.Where(x => !localAttendanceIds.Contains(x.Id)).AsNoTracking().ToList(); // await _remoteContext.Attendances.AddRangeAsync(toUpload); await _localContext.Attendances.AddRangeAsync(toDownload); var i = await _localContext.SaveChangesAsync(); if (i > 0) { ApplicationSetting.DatabaseServer = remoteAppSetting.DatabaseServer; ApplicationSetting.DatabaseName = remoteAppSetting.DatabaseName; ApplicationSetting.DbPassword = StringCipher.Decrypt(remoteAppSetting.DbPassword); ApplicationSetting.DbUsername = remoteAppSetting.DbUsername; return(""); } return("Synchronization failed. Try again"); } catch (Exception e) { throw e; } }