예제 #1
0
        public async Task <IActionResult> EditAbsent(Absent absent, int id)
        {
            Absent absent1 = await _payrollDb.Absents.FindAsync(id);

            if (ModelState.IsValid)
            {
                if (absent1 != null)
                {
                    absent1.Reason     = absent.Reason;
                    absent1.AbsentDate = absent.AbsentDate;

                    absent1.WorkerId = absent.WorkerId;
                    await _payrollDb.SaveChangesAsync();

                    return(RedirectToAction(nameof(ListAbsent)));
                }

                else
                {
                    return(Redirect("~/Account/Error"));
                }
            }
            else
            {
                return(View());
            }
        }
예제 #2
0
        public ActionResult AddAbsent(AbsentClassDto absentDto)
        {
            if (absentDto.StudentID != null)
            {
                var persianDateFrom = PersianDateTime.Parse(absentDto.FromDate);
                var persianDateTo   = PersianDateTime.Parse(absentDto.ToDate);

                var absent = new Absent
                {
                    StudentID     = int.Parse(absentDto.StudentID),
                    FromDate      = persianDateFrom.ToDateTime(),
                    ToDate        = persianDateTo.ToDateTime(),
                    IsCertificate = absentDto.IsCertificate,
                    Problem       = absentDto.Problem,
                    IsTrue        = absentDto.IsTrue,
                };

                try
                {
                    _context.Absents.Add(absent);
                    _context.SaveChanges();
                    ModelState.Clear();
                    return(Content("اطلاعات وارد شد"));
                }
                catch (Exception exc)
                {
                    throw;
                }
            }
            else
            {
                return(Content("صحیح نمیباشد"));
            }
        }
예제 #3
0
 public void AddAbsentItem(Absent item)
 {
     foreach (Absent absent in _classAbsentList)
     {
         if ((absent.StudentID == item.StudentID) && (absent.AbsenceWeekIndex == item.AbsenceWeekIndex) && (absent.AbsenceClassIndex == item.AbsenceClassIndex))
         {
             throw new ItemExistException("该记录已存在!");
         }
     }
 }
 public ActionResult CreatAbsents(Absent emp)
 {
     if (ModelState.IsValid)
     {
         context.Absents.Add(emp);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
예제 #5
0
        public List <Absent> getAbsents(int StdID)
        {
            List <Absent> StdAbsents = new List <Absent>();
            string        sql        = "select * from Std_Absent where StudentID = " + StdID.ToString();
            DataTable     dt         = DataAccess.ExecuteSQLQuery(sql);

            foreach (DataRow dr in dt.Rows)
            {
                Absent s = new Absent();
                s.ID   = Convert.ToInt32(dr["ID"].ToString());
                s.Date = Convert.ToDateTime(dr["AbsentDate"].ToString());
                StdAbsents.Add(s);
            }
            return(StdAbsents);
        }
        protected override void ExecuteOperation(IEntity entity)
        {
            Period p = entity as Period;

            repository.Add(p);

            foreach (var item in p.ApsentStudents)
            {
                Absent a = new Absent()
                {
                    Period = p, Student = item
                };

                repository.Add(a);
            }
        }
예제 #7
0
        private void listBox_Subjects_SelectedIndexChanged(object sender, EventArgs e)
        {
            flowLayoutPanel_Absents.Controls.Clear();
            studentAbsents.Clear();
            chechBoxs.Clear();

            int index            = listBox_Subjects.SelectedIndex;
            var selectedSchedule = _data.Schedules
                                   .Where(t => t.GroupId == selectedGroupId && t.Day.Equals(selectedDate.DayOfWeek.ToString()))
                                   .OrderBy(t => t.Number)
                                   .ToList()[index];

            var studentsList = new HashSet <Student>(_data.Students
                                                     .Where(t => t.GroupId == selectedGroupId)
                                                     .OrderBy(t => t.FullName));

            foreach (var student in studentsList)
            {
                var absents = _data.Absents
                              .Where(t => t.ScheduleId == selectedSchedule.Id &&
                                     t.StudentId == student.Id &&
                                     Comparator.Equals(t.Date, selectedDate));
                if (absents.Count() > 0)
                {
                    flowLayoutPanel_Absents.Controls.Add(ElementMaker
                                                         .CreateContainerLine(student.FullName, absents.First().Cause, chechBoxs));
                    studentAbsents.Add(student, absents.First());
                }
                else
                {
                    flowLayoutPanel_Absents.Controls.Add(ElementMaker
                                                         .CreateContainerLine(student.FullName, Absent.PRESENT, chechBoxs));
                    Absent absent = new Absent {
                        Id         = _data.Absents.Count,
                        Cause      = Absent.PRESENT,
                        Date       = selectedDate,
                        ScheduleId = selectedSchedule.Id,
                        StudentId  = student.Id
                    };
                    studentAbsents.Add(student, absent);
                    _data.Absents.Add(absent);
                }
                _data.SaveChanges(DataContext.ABSENT);
            }
        }
예제 #8
0
        public async Task <IActionResult> CreateAbsent(Absent absent)
        {
            if (ModelState.IsValid)
            {
                Absent p = absent;

                var workerAbsent = await _payrollDb.Absents.Where(x => x.WorkerId == p.WorkerId && x.Attandence == 0).ToListAsync();

                if (workerAbsent.Count == 5)
                {
                    foreach (var item in workerAbsent)
                    {
                        nese    = item.AbsentDate.Day;
                        result += nese;
                    }

                    if ((result % 5) == 0)
                    {
                        foreach (var item in workerAbsent)
                        {
                            for (var i = 0; i < item.AbsentDate.Day; i++)
                            {
                                var nese = item.AbsentDate.Day;
                                if ((result / nese) == 5)
                                {
                                    return(RedirectToAction("ListXitam", "Xitam"));
                                }
                            }
                        }
                    }
                }
                await _payrollDb.Absents.AddAsync(p);

                await _payrollDb.SaveChangesAsync();

                return(RedirectToAction(nameof(ListAbsent)));
            }
            else
            {
                return(View());
            }
        }
        public async Task <IActionResult> Absent(AbsentModel model)
        {
            if (_signInManager.Context.User.Identity.IsAuthenticated)
            {
                if (HttpContext.User.IsInRole("Hr"))
                {
                    await Initializer.InitialLayout("Employees", ViewBag, _db, _signInManager, "Employee Attendance");

                    List <Employee> employees = await _db.Employees.ToListAsync();

                    List <Absent> Absents = await _db.Absents.Where(wc => wc.From.Year == DateTime.Now.Year && wc.From.Month == DateTime.Now.Month && wc.EmployeeId == model.EmployeeId).ToListAsync();

                    List <Absent> annualAbsents = await _db.Absents.Where(a => a.From.Year == DateTime.Now.Year && a.EmployeeId == model.EmployeeId).ToListAsync();

                    Employee employee = await _db.Employees
                                        .Where(e => e.Id == model.EmployeeId)
                                        .FirstOrDefaultAsync();

                    AbsentModel wcm = new AbsentModel();
                    if (ModelState.IsValid)
                    {
                        bool IsExist = false;
                        if (model.From == model.To)
                        {
                            ModelState.AddModelError("", "From and To must not be equal");
                        }
                        else if (model.From < employee.LastCalculate)
                        {
                            ModelState.AddModelError("", "You can't add this time arrange");
                        }
                        else
                        {
                            foreach (Absent absent in Absents)
                            {
                                if (absent.From <= model.From && absent.To >= model.From)
                                {
                                    IsExist               = true;
                                    absent.From           = model.From;
                                    absent.To             = model.To;
                                    absent.PermissionRole = model.PermissionRole;
                                    absent.Reason         = model.Reason;
                                    absent.EmployeeId     = model.EmployeeId;
                                    if (absent.From.Day - absent.To.Day == 5)
                                    {
                                        Work work = await _db.Works
                                                    .Where(w => w.EmployeeId == absent.EmployeeId && w.LeaveTime == DateTime.MinValue)
                                                    .FirstOrDefaultAsync();

                                        work.LeaveTime = absent.To;
                                        work.Reason    = "5 gün və artıq işə gəlməməsi";
                                    }
                                    await _db.SaveChangesAsync();

                                    break;
                                }
                            }
                            if (!IsExist)
                            {
                                Absent absent = new Absent
                                {
                                    From           = model.From,
                                    To             = model.To,
                                    PermissionRole = model.PermissionRole,
                                    EmployeeId     = model.EmployeeId,
                                    Reason         = model.Reason
                                };
                                await _db.Absents.AddAsync(absent);

                                if (absent.From.Day - absent.To.Day == 5)
                                {
                                    Work work = await _db.Works
                                                .Where(w => w.EmployeeId == absent.EmployeeId && w.LeaveTime == DateTime.MinValue)
                                                .FirstOrDefaultAsync();

                                    work.LeaveTime = absent.To;
                                    work.Reason    = "5 gün və artıq işə gəlməməsi";
                                }
                                await _db.SaveChangesAsync();
                            }
                        }
                        Absents = await _db.Absents.Where(wc => wc.From.Year == DateTime.Now.Year && wc.From.Month == DateTime.Now.Month && wc.EmployeeId == model.EmployeeId).ToListAsync();
                    }
                    else
                    {
                        wcm.From           = model.From;
                        wcm.To             = model.To;
                        wcm.PermissionRole = model.PermissionRole;
                        wcm.Reason         = model.Reason;
                        wcm.EmployeeId     = model.EmployeeId;
                        Absents            = await _db.Absents.Where(wc => wc.From.Year == DateTime.Now.Year && wc.From.Month == DateTime.Now.Month && wc.EmployeeId == model.EmployeeId).ToListAsync();
                    }
                    wcm.Employees     = employees;
                    wcm.Absents       = Absents;
                    wcm.AnnualAbsents = annualAbsents;
                    wcm.LastCheckDate = DateTime.Now;
                    return(View(wcm));
                }
            }
            return(RedirectToAction("Forbidden", "Error"));
        }
예제 #10
0
 public void AddAbsent(Student student)
 {
     Absent.Add(student);
 }