예제 #1
0
        // clean up the database
        public override void Clear()
        {
            base.Clear();
            var cacheEntry = db.UserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == userId);

            db.UserTokenCacheList.Remove(cacheEntry);
            db.SaveChanges();
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "Id,Name")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Student.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
        public ActionResult Create([Bind(Include = "id,name,email,uniqid,roleid")] teacherlist teacherlist)
        {
            if (ModelState.IsValid)
            {
                db.teacherlists.Add(teacherlist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(teacherlist));
        }
        public ActionResult Create([Bind(Include = "ModuleId,ModuleName")] Module module)
        {
            if (ModelState.IsValid)
            {
                db.Modules.Add(module);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(module));
        }
예제 #5
0
        public ActionResult Create([Bind(Include = "id,name,sem,year,batch")] subpracticallist subpracticallist)
        {
            if (ModelState.IsValid)
            {
                db.subpracticallists.Add(subpracticallist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(subpracticallist));
        }
예제 #6
0
        public ActionResult Create([Bind(Include = "id,stdrollno,stdname,total_theory,theory_percentage,total_practical,practical_percentage,extra_attendance,total_attendance,attendance_percentage")] SEdefaulters sEdefaulters)
        {
            if (ModelState.IsValid)
            {
                db.SEdefaulters.Add(sEdefaulters);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sEdefaulters));
        }
        public ActionResult Create([Bind(Include = "Id,Number,Name")] ClassRoom classRoom)
        {
            if (ModelState.IsValid)
            {
                db.ClassRoom.Add(classRoom);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(classRoom));
        }
        public ActionResult Create([Bind(Include = "Id,Date,IsPresent,IdStudent,IdClassRoom")] Attendance attendance)
        {
            if (ModelState.IsValid)
            {
                db.Attendance.Add(attendance);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IdClassRoom = new SelectList(db.ClassRoom, "Id", "Name", attendance.IdClassRoom);
            ViewBag.IdStudent   = new SelectList(db.Student, "Id", "Name", attendance.IdStudent);
            return(View(attendance));
        }
예제 #9
0
        public void MarkAttendance(Guid machineId, MarkAttendanceDTO attendanceDTO)
        {
            /*
             * 1. Get the domain
             * 2. Let domain handle calls
             * 3. Persist the changes
             */
            AttendanceEvent attendanceMachine =
                context.AttendanceEvents.Find(machineId);

            attendanceMachine.Mark(attendanceDTO.PersonId, attendanceDTO.AttendanceEntry, attendanceDTO.Date);
            context.SaveChanges();
        }
예제 #10
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,Name,RankId,Email,IsActive")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                employee.BrigadeId = Helpers.Brigade.CurrentBrigade().Value;
                context.Employees.Add(employee);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Ranks = new SelectList(context.Ranks.OrderBy(r => r.Description), "Id", "Description", employee.RankId);
            return(View(employee));
        }
예제 #11
0
        /// <summary>
        /// Method to Save Report Data
        /// </summary>
        /// <param name="report">Report</param>
        /// <returns><c>true</c> if Report data is successfully saved else returns <c>false</c></returns>
        public bool SaveReportData(Report report)
        {
            bool isReportDataSaved = false;

            try
            {
                if (report != null && report.ReportDataList != null && report.ReportDataList.Count > 0)
                {
                    ReportEntity rptEntity = new ReportEntity()
                    {
                        Name       = report.Name,
                        ImportDate = DateTime.Now
                    };

                    db.Report.Add(rptEntity);
                    db.SaveChanges();

                    foreach (var reportData in report.ReportDataList)
                    {
                        ReportDataEntity rptDataEntity = new ReportDataEntity()
                        {
                            ReportId      = rptEntity.ReportId,
                            Node          = reportData.Node,
                            Panel         = reportData.Panel,
                            Event         = reportData.Event,
                            EventDateTime = reportData.EventDateTime,
                            CardNumber    = reportData.CardNumber,
                            CardName      = reportData.CardName,
                            Location      = reportData.Location,
                            ReaderId      = reportData.ReaderId,
                            In            = reportData.In,
                            Out           = reportData.Out,
                            Affiliation   = reportData.Affiliation,
                            AlarmText     = reportData.AlarmText,
                            EmployeeName  = ExtractEmployeeFirstName(reportData.CardName) + " " + ExtractEmployeeLastName(reportData.CardName),
                            EmployeeCode  = ExtractEmployeeCode(reportData.CardName)
                        };

                        db.ReportData.Add(rptDataEntity);
                    }

                    db.SaveChanges();
                    isReportDataSaved = true;
                }
            }
            catch (Exception ex) {
                throw ex;
            }
            return(isReportDataSaved);
        }
예제 #12
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,EmployeeId,JobId,StartDateTime,EndDateTime")] Models.Attendance attendance)
        {
            if (ModelState.IsValid)
            {
                db.Attendances.Add(attendance);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            int brigadeId = Helpers.Brigade.CurrentBrigade().Value;

            ViewBag.Employees = new SelectList(db.Employees.Where(e => e.BrigadeId == brigadeId).OrderBy(e => e.Name), "Id", "Name");
            ViewBag.Jobs      = new SelectList(db.Jobs.Where(j => j.BrigadeId == brigadeId).OrderBy(j => j.Description), "Id", "Description");
            return(View(attendance));
        }
예제 #13
0
        public string AddSessionSemester(SessionSemester newSem)
        {
            try
            {
                if (_context.SessionSemesters.Any(a => a.Session == newSem.Session && a.Semester == newSem.Semester && !a.IsDeleted))
                {
                    return("Session and Semester already exist");
                }

                if (newSem.IsActive)
                {
                    var allsems = _context.SessionSemesters.Where(a => !a.IsDeleted).ToList();
                    foreach (var item in allsems)
                    {
                        item.IsActive = false;
                    }
                }

                newSem.Id = Guid.NewGuid().ToString();
                _context.SessionSemesters.Add(newSem);


                if (_context.SaveChanges() > 0)
                {
                    if (newSem.IsActive)  //change the active semester on local sqlite
                    {
                        LoggedInUser.ActiveSession = newSem;
                        var localSems = _localContext.SessionSemesters.Where(a => !a.IsDeleted).ToList();
                        foreach (var item in localSems)
                        {
                            item.IsActive = false;
                        }

                        _localContext.SaveChanges();
                    }

                    return("");
                }
                else
                {
                    return("Session/Semester could not be added");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public ActionResult Index(List <Users> users, DateTime selectedDate, Attendance attendance)
 {
     if (DateTime.Compare(DateTime.MinValue, selectedDate) != 0)
     {
         var AttendanceList = from x in _context.Attendance select x;
         var c = AttendanceList.FirstOrDefault(a => a.Attendance_Date.Equals(selectedDate));
         if (c == null)
         {
             foreach (var i in users)
             {
                 Attendance attendanceAdd = new Attendance();
                 attendanceAdd.Name              = i.Name;
                 attendanceAdd.Attendance_Date   = selectedDate;
                 attendanceAdd.Attendance_status = i.Temporary_status;
                 _context.Add(attendanceAdd);
                 _context.SaveChanges();
             }
             return(RedirectToAction("Index", "Attendances"));
         }
         else
         {
             ViewBag.Message = "Samedate";
             return(View(_context.Users.ToList()));
         }
     }
     else
     {
         ViewBag.Message = "nullDate";
         return(View(_context.Users.ToList()));
     }
 }
예제 #15
0
        public ActionResult InitClass(string TeacherId)
        {
            if (Convert.ToInt32(TeacherId) > 0)
            {
                using (AttendanceContext db = new AttendanceContext())
                {
                    String uniqueCode = DateTime.Now.Ticks.ToString("x");
                    db.Init.Add(new Init()
                    {
                        Code      = uniqueCode,
                        Status    = "Started",
                        TeacherId = Convert.ToInt32(TeacherId)
                    });
                    db.SaveChanges();
                    var teacherToInt = int.Parse(TeacherId);
                    var obj          = db.Init.Where(a => a.TeacherId.Equals(teacherToInt) && a.Status.Equals("Started")).FirstOrDefault();
                    var teacher      = db.Teachers.Where(a => a.Id.Equals(teacherToInt)).FirstOrDefault();

                    var createStarted = new StartedClasses
                    {
                        InitId      = obj.Id,
                        Code        = obj.Code,
                        TeacherId   = obj.TeacherId,
                        TeacherName = teacher.FirstName
                    };


                    return(View(createStarted));
                }
            }
            return(View("Index"));
        }
예제 #16
0
        public string SaveAttendance(string courseId, string studentId, string semesterId, string markedBy)
        {
            try
            {
                var dateMarked = DateTime.Now;

                var courseRegId = _context.CourseRegistrations.SingleOrDefault(a => a.CourseId == courseId && a.SessionSemesterId == semesterId && a.StudentId == studentId)?.Id;

                if (courseRegId == null)
                {
                    return("You are not registered for this course this semester");
                }

                if (_context.Attendances.Any(a => a.CourseRegistrationId == courseRegId && a.DateMarked.Date == dateMarked.Date))
                {
                    return("You have marked attendance for this course today");
                }

                _context.Attendances.Add(new Attendance
                {
                    Id = Guid.NewGuid().ToString(),
                    CourseRegistrationId = courseRegId,
                    DateMarked           = dateMarked,
                    MarkedBy             = markedBy
                });

                return(_context.SaveChanges() > 0 ? "" : "Attendance could not be saved");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #17
0
        public string UpdateSetting(AppSetting setting)
        {
            var oldSetting = _context.AppSettings.FirstOrDefault();

            if (oldSetting == null)
            {
                return("Setting not found");
            }

            oldSetting.ApplicationName = setting.ApplicationName;
            oldSetting.Title           = setting.Title;
            oldSetting.SubTitle        = setting.SubTitle;
            oldSetting.LogoBase64      = setting.LogoBase64;
            oldSetting.PrimaryColor    = setting.PrimaryColor;
            oldSetting.SecondaryColor  = setting.SecondaryColor;

            // do on local
            var _localContext   = Helper.GetDataContext(true);
            var oldSettingLocal = _localContext.AppSettings.First();

            oldSettingLocal.ApplicationName = setting.ApplicationName;
            oldSettingLocal.Title           = setting.Title;
            oldSettingLocal.SubTitle        = setting.SubTitle;
            oldSettingLocal.LogoBase64      = setting.LogoBase64;
            oldSettingLocal.PrimaryColor    = setting.PrimaryColor;
            oldSettingLocal.SecondaryColor  = setting.SecondaryColor;
            _localContext.SaveChanges();

            return(_context.SaveChanges() > 0 ? "" : "Settings could not be updated");
        }
        public ActionResult Index(List <Attendance> attendances, DateTime SearchString)
        {
            var filterresults = from x in _context.Attendance select x;

            if (DateTime.Compare(DateTime.MinValue, SearchString) == 0)
            {
                foreach (var i in attendances)
                {
                    var c = filterresults.Where(a => a.AttendanceID.Equals(i.AttendanceID)).FirstOrDefault();
                    if (c != null)
                    {
                        c.Attendance_status = i.Attendance_status;
                    }
                }
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            if (SearchString != null)
            {
                filterresults = filterresults.Where(x => DateTime.Compare(x.Attendance_Date, SearchString) == 0);

                return(View(filterresults.ToList()));
            }
            return(View(attendances));
        }
예제 #19
0
        public string RegisterCourseStudents(List <BulkStudentCourseReg> model, string courseId)
        {
            try
            {
                var studentRepo = new StudentRepo();
                var levelRepo   = new LevelRepo();
                var sessionRepo = new SessionSemesterRepo();

                var activeSession = sessionRepo.GetActiveSessionSemester(); //LoggedInUser.ActiveSession;
                if (activeSession == null)
                {
                    return("You can't register students for course. There is no active semester");
                }

                var toAdd = new List <CourseRegistration>();
                foreach (var item in model)
                {
                    var student = studentRepo.GetStudentByMatricNo(item.MatricNumber);
                    var levelId = levelRepo.GetLevelId(item.Level);
                    if (student == null || levelId == null)
                    {
                        return("No record saved. At least one student or level does not exist");
                    }

                    if (!_context.CourseRegistrations.Any(a => a.StudentId == student.Id && a.CourseId == courseId && a.SessionSemesterId == activeSession.Id))
                    {
                        toAdd.Add(new CourseRegistration
                        {
                            CourseId          = courseId,
                            DateRegistered    = DateTime.Now,
                            Id                = Guid.NewGuid().ToString(),
                            StudentId         = student.Id,
                            LevelId           = levelId,
                            SessionSemesterId = activeSession.Id,
                            RegisteredBy      = LoggedInUser.UserId,
                        });
                    }
                }
                _context.CourseRegistrations.AddRange(toAdd);
                return(_context.SaveChanges() > 0 ? "" : "No record saved");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Create(studentlist std)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.studentlists.Add(std);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(std));
            }
            catch
            {
                return(View());
            }
        }
예제 #21
0
 public ActionResult AddClassRoom(ClassRoom classRoom)
 {
     if (ModelState.IsValid)
     {
         db.ClassRooms.Add(classRoom);
         db.SaveChanges();
     }
     return(View());
 }
예제 #22
0
        public string AddTitle(PersonTitle newTitle)
        {
            try
            {
                if (_context.Titles.Any(a => a.Title == newTitle.Title && !a.IsDeleted))
                {
                    return("Title already exists");
                }

                newTitle.Id = Guid.NewGuid().ToString();
                _context.Titles.Add(newTitle);
                return(_context.SaveChanges() > 0 ? "" : "Title could not be added");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #23
0
        public string AddStudent(StudentDetail newStudent)
        {
            try
            {
                if (_context.Students.Any(a => a.MatricNo == newStudent.MatricNo || a.Email == newStudent.Email && !a.IsDeleted))
                {
                    return("Student with this Matric number or Email address exists");
                }

                newStudent.Id = Guid.NewGuid().ToString();
                _context.Students.Add(newStudent);
                return(_context.SaveChanges() > 0 ? "" : "Student could not be added");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #24
0
        public ActionResult Create([Bind(Include = "id,name,sem,year,mode")] subjectlist subjectlist)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.subjectlists.Add(subjectlist);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(subjectlist));
            }
            catch
            {
                return(View());
            }
        }
예제 #25
0
        public string AddDepartment(Department newDepartment)
        {
            try
            {
                if (_context.Departments.Any(a => a.DepartmentCode == newDepartment.DepartmentCode || a.DepartmentName == newDepartment.DepartmentName && !a.IsDeleted))
                {
                    return("Department with this name or Department Code exists");
                }

                newDepartment.Id = Guid.NewGuid().ToString();
                _context.Departments.Add(newDepartment);
                return(_context.SaveChanges() > 0 ? "" : "Department could not be added");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #26
0
        public string AddCourse(Course newCourse)
        {
            try
            {
                if (_context.Courses.Any(a => a.CourseCode == newCourse.CourseCode || a.CourseTitle == newCourse.CourseTitle && a.DepartmentId == newCourse.DepartmentId && !a.IsDeleted))
                {
                    return("Course with this Title or Course Code exists");
                }

                newCourse.Id = Guid.NewGuid().ToString();
                _context.Courses.Add(newCourse);
                return(_context.SaveChanges() > 0 ? "" : "Course could not be added");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #27
0
 public ActionResult AddStudent(Student student)
 {
     if (ModelState.IsValid)
     {
         db.Students.Add(student);
         db.SaveChanges();
     }
     return(View());
 }
예제 #28
0
        public AttendanceController(AttendanceContext context)
        {
            _context = context;

            if (_context.Attendances.Count() == 0)
            {
                NoContent();
                _context.SaveChanges();
            }
        }
예제 #29
0
        public string AssignCourse(StaffCourse model)
        {
            try
            {
                if (_context.StaffCourses.Any(a => a.StaffId == model.StaffId && a.CourseId == model.CourseId))
                {
                    return("Course already assigned to staff");
                }

                model.Id           = Guid.NewGuid().ToString();
                model.DateAssigned = DateTime.Now;
                _context.StaffCourses.Add(model);

                return(_context.SaveChanges() > 0 ? "" : "Course could not be assigned to staff");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #30
0
 public IActionResult NewRecord([FromBody] Attendance attendance)
 {
     if (attendance == null)
     {
         return(BadRequest());
     }
     _context.Attendances.Add(attendance);
     _context.SaveChanges();
     return(new ObjectResult(_context.Attendances));
     //return CreatedAtRoute("GetUser", new { id = user.id }, user);
 }