Пример #1
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));
        }
Пример #2
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));
        }
Пример #3
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));
        }
Пример #4
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));
        }
Пример #5
0
        public async Task <IActionResult> Create_Ad([Bind("Id,Name,Password,Role,Tel,Email,Nationality,DateOfBirth,Address")] People people)
        {
            Debug.WriteLine($"Value: {people.Name}, {people.Email}");
            if (CheckExist(people.Name))
            {
                Debug.WriteLine("This run");
                return(RedirectToAction(nameof(AdminTable)));
            }

            if (ModelState.IsValid)
            {
                Debug.WriteLine("Model valid");
                _context.Add(people);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(AdminTable)));
            }
            return(RedirectToAction(nameof(AdminTable)));
        }
        public async Task <IActionResult> Create_Ad([Bind("Id,Name,Password,Role,Tel,Email,Nationality,DateOfBirth,Address")] People people)
        {
            if (HttpContext.Session.GetString("Session_Role") == veryrole)
            {
                if (CheckExist(people.Name))
                {
                    return(RedirectToAction(nameof(AdminTable)));
                }

                if (ModelState.IsValid)
                {
                    _context.Add(people);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(AdminTable)));
                }
                return(RedirectToAction(nameof(AdminTable)));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }