Exemple #1
0
        public HttpResponseMessage Get(DateTime date)
        {
            try
            {
                Models.KehadiranContext context = new Models.KehadiranContext();
                if (context.IsHoliday(date))
                {
                    throw new SystemException(date.ToShortDateString() + " adalah hari libur");
                }

                using (var db = new OcphDbContext())
                {
                    var result = db.Pegawai.Select().ToList();
                    foreach (var item in result)
                    {
                        var res = db.Absen.Where(x => x.PegawaiId == item.Id)
                                  .Where(O => O.Tanggal.Day == date.Day && O.Tanggal.Month == date.Month && O.Tanggal.Year == date.Year).ToList();

                        var lap = context.Perizinan(date, item.Id);
                        lap.Hadir    = res.Where(O => O.Status == StatusKehadiran.Hadir).Count();
                        lap.Libur    = context.TotalLibur;
                        item.Sumarry = lap;
                    }



                    return(Request.CreateResponse(HttpStatusCode.OK, result));
                }
            }
            catch (Exception ex)
            {
                return(new ErrorResponse(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message), ex.Message));
            }
        }
Exemple #2
0
        public HttpResponseMessage GetMingguan(DateTime date)
        {
            try
            {
                using (var db = new OcphDbContext())
                {
                    var      manage = new DateManage(date);
                    DateTime first  = manage.FirstDayOfWeek;
                    DateTime last   = manage.LastDayOfWeek;
                    Models.KehadiranContext context = new Models.KehadiranContext(first, last);
                    var result = db.Pegawai.Select().ToList();
                    if (result != null)
                    {
                        foreach (var item in result)
                        {
                            var res = db.Absen.Where(x => x.PegawaiId == item.Id).Where(O => O.Tanggal.Day >= first.Day && O.Tanggal.Month >= first.Month && O.Tanggal.Year >= first.Year &&
                                                                                        O.Tanggal.Day <= last.Day && O.Tanggal.Month <= last.Month && O.Tanggal.Year <= last.Year).ToList();

                            var lap = context.Perizinan(first, last, item.Id);
                            lap.Hadir = res.Where(O => O.Status == StatusKehadiran.Hadir).Count();
                            lap.Libur = context.TotalLibur;
                            Tuple <int, int, int> hasil = context.HitungTerlambat(res);
                            lap.Terlambat   = hasil.Item1;
                            lap.CepatPulang = hasil.Item2;
                            lap.Lembur      = hasil.Item3;
                            item.Sumarry    = lap;
                        }
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK, result));
                }
            }
            catch (Exception ex)
            {
                return(new ErrorResponse(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message), ex.Message));
            }
        }