Пример #1
0
        public async Task <IActionResult> DeleteAdmin(int id)
        {
            var people = await _context.People.FindAsync(id);

            _context.People.Remove(people);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(AdminTable)));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Password,Role,Tel,Email")] People people)
        {
            if (ModelState.IsValid)
            {
                _context.Add(people);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(people));
        }
        public async Task <IActionResult> DeleteAdmin(int id)
        {
            if (HttpContext.Session.GetString("Session_Role") == veryrole)
            {
                var people = await _context.People.FindAsync(id);

                _context.People.Remove(people);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(AdminTable)));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Пример #4
0
        public async Task <IActionResult> AddAttendance([FromBody] List <Attendance> attendance)
        {
            var result            = attendance.Count();
            var attendance_record = _context.Attendance.Where(e => e.EmployeeId == attendance[0].EmployeeId);
            var date  = attendance_record.Select(a => a.Date.ToShortDateString()).ToList();
            var empId = attendance[0].EmployeeId;

            foreach (var a in attendance)
            {
                var input_date = a.Date.AddDays(1).Date;
                if (date.Contains(input_date.ToShortDateString()))
                {
                    Debug.WriteLine($"This part run {input_date}");
                    var update_row = await attendance_record.FirstAsync(r => r.Date.Date == input_date);

                    update_row.Status = a.Status;
                    await _context.SaveChangesAsync();
                }
                else
                {
                    a.Date = a.Date.AddDays(1);
                    _context.Add(a);
                    await _context.SaveChangesAsync();
                }
            }

            return(Json(result));
        }
Пример #5
0
        public async Task <IActionResult> AddAttendance([FromBody] List <Attendance> attendance)
        {
            var result          = attendance.Count();
            var date_in_context = await _context.Attendance.Select(a => a.Date.ToShortDateString()).ToListAsync();

            foreach (var a in attendance)
            {
                if (date_in_context.Contains(a.Date.AddDays(1).ToShortDateString()))
                {
                    DateTime dt;
                    var      date = DateTime.TryParse(a.Date.AddDays(1).ToShortDateString(), out dt);
                    Debug.WriteLine("This date is already exists");
                    Debug.WriteLine($"Record {date} {a.Status} {a.EmployeeId}");
                    var exist_record = await _context.Attendance.FirstAsync(r => r.EmployeeId == a.EmployeeId && r.Date == dt);

                    exist_record.Status = a.Status;


                    Debug.WriteLine($"Existing record {exist_record.EmployeeId} {exist_record.Date} {exist_record.Status}");
                }
                else
                {
                    a.Date = a.Date.AddDays(1);
                    _context.Add(a);
                }
                await _context.SaveChangesAsync();

                a.Date = a.Date.AddDays(1);
            }

            return(Json(result));
        }
Пример #6
0
        public async Task <IActionResult> AddAttendance([FromBody] List <Attendance> attendance)
        {
            var result = attendance.Count();

            foreach (var a in attendance)
            {
                _context.Add(a);
                await _context.SaveChangesAsync();
            }

            return(Json(result));
        }