Exemple #1
0
        private Task <Absen> absen(Absen absenToday, int karyawanId, AbsenType type)
        {
            var    saveResult = 0;
            string message    = string.Empty;

            if (absenToday == null)
            {
                absenToday = new Absen {
                    KaryawanId = karyawanId, AbsenType = type, Masuk = DateTime.Now
                };
                //Add to _db.Absen.Add(absenToday);
                saveResult = 1;// await _db.SaveChangesAsync();
                return(saveResult > 0 ? Task.FromResult(absenToday) : throw new SystemException("Absen Gagal!, Coba Ulangi Lagi"));
            }

            if (absenToday.Masuk != null && absenToday.Pulang == null)
            {
                var now = new DateTime(2020, 9, 16, 8, 0, 0);
                if (now.Subtract(absenToday.Masuk.Value) < new TimeSpan(1, 0, 0))
                {
                    throw new SystemException($"Anda Sudah Absen Masuk {type} Hari Ini !");
                }
                else
                {
                    absenToday.Pulang = now;
                    saveResult        = 1;// await _db.SaveChangesAsync();
                    return(saveResult > 0 ? Task.FromResult(absenToday) : throw new SystemException("Absen Gagal!, Coba Ulangi Lagi"));
                }
            }
            throw new SystemException($"Anda Sudah Absen Pulang {type} Hari Ini !");
        }
Exemple #2
0
        public async Task <Absen> absen(int karyawanId, AbsenType type)
        {
            var now        = DateTime.Now;
            var absenToday = _db.Absen.Where(x => x.KaryawanId == karyawanId && x.AbsenType == type &&
                                             (x.Masuk.Value.Year == now.Year && x.Masuk.Value.Month == now.Month && x.Masuk.Value.Day == now.Day)).FirstOrDefault();
            int saveResult = 0;

            if (absenToday == null)
            {
                absenToday = new Absen {
                    KaryawanId = karyawanId, AbsenType = type, Masuk = now
                };
                _db.Absen.Add(absenToday);
                saveResult = await _db.SaveChangesAsync();
            }
            else if (absenToday.Pulang != null)
            {
                throw new SystemException($"Maaf Anda Sudah Absen {type.ToString()} Hari Ini ");
            }
            else
            {
                absenToday.Pulang = now;
                saveResult        = await _db.SaveChangesAsync();
            }

            return(saveResult > 0 ? absenToday : throw new SystemException("Maaf Terjadi Kesalahan Coba Ulangi Lagi !"));
        }