Пример #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 !");
        }
Пример #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 !"));
        }
Пример #3
0
        public async Task Absen_IsNew_MustBeSuccessAddIn()
        {
            var   type       = AbsenType.Kerja;
            Absen absenToday = null;
            var   result     = await absen(absenToday, 1, type);

            Assert.NotNull(result);
        }
Пример #4
0
        public void Absen_AlradyIn_And_AlradyOut_MustBe_throwExecption()
        {
            var now        = new DateTime(2020, 9, 16, 7, 0, 0);
            var type       = AbsenType.Kerja;
            var absenToday = new Absen {
                KaryawanId = 1, AbsenType = type, Pulang = new DateTime(2020, 9, 16, 7, 30, 0), Masuk = new DateTime(2020, 9, 16, 7, 30, 0)
            };

            Assert.Throws(typeof(SystemException), new TestDelegate(() => absen(absenToday, 1, type)));
        }
Пример #5
0
        public async Task Absen_AlradyIn_MustBeSuccessAddOut()
        {
            var now        = new DateTime(2020, 9, 16, 8, 10, 0);
            var type       = AbsenType.Kerja;
            var absenToday = new Absen {
                KaryawanId = 1, AbsenType = type, Masuk = new DateTime(2020, 9, 16, 7, 0, 0)
            };
            var result = await absen(absenToday, 1, type);

            Assert.NotNull(result.Pulang);
        }
Пример #6
0
 public async Task AddAbsen(Absen absen)
 {
     try
     {
         var result = _db.Absens.Add(absen);
         await _db.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         throw new SystemException(ex.Message);
     }
 }
Пример #7
0
 public IActionResult Put(int id, [FromBody] Absen value)
 {
     try
     {
         var result = _context.Level.Where(x => x.Id == value.Id).FirstOrDefault();
         var saved  = _context.SaveChanges();
         if (saved <= 0)
         {
             throw new SystemException("Data Perusahaan  Tidak Berhasil Disimpan !");
         }
         return(Ok(value));
     }
     catch (System.Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #8
0
        public async Task <IActionResult> DoAbsen()
        {
            try
            {
                var userName = User.Identity.Name;
                if (string.IsNullOrEmpty(userName))
                {
                    return(Unauthorized("Maaf, Anda Tidak Memiliki Access !"));
                }
                Absen result = await _absenService.DoAbsen(userName);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #9
0
 private void AbsenCommandAction(object obj)
 {
     try
     {
         var dataAbsen = new absen
         {
             IdMahasiswa = idAnggota, Tanggal = today
         };
         var isSaved = Absen.Add(dataAbsen);
         SourceView.Refresh();
         Helpers.ShowSuccessMessage("Anda Sudah Absen");
         IdAnggota = null;
     }
     catch (Exception ex)
     {
         Helpers.ShowErrorMessage(ex.Message);
     }
 }
Пример #10
0
        public async Task <IActionResult> Post([FromBody] Absen value)
        {
            try
            {
                var result = await _absen.absen(value.KaryawanId, value.AbsenType);

                if (result == null)
                {
                    throw new SystemException("Data Perusahaan  Tidak Berhasil Disimpan !");
                }
                var message = new NotificationModel("System", "Absen",
                                                    $"Anda Telah Berhasil Absen {value.AbsenType} !", NotificationType.Private);
                message.UserId = value.Karyawan.UserId;
                await _fcm.SendMessagePrivate(message, value.Karyawan.DeviceId);

                return(Ok(result));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #11
0
        private Absen Save(int karyawanId)
        {
            var _absenSetting = _appSetting.AbsenSetting;

            try
            {
                var now = DateTime.Now;

                var masuk = new DateTime(now.Year, now.Month, now.Day, _absenSetting.Masuk.Hours,
                                         _absenSetting.Masuk.Minutes, _absenSetting.Masuk.Seconds);

                var pulang = new DateTime(now.Year, now.Month, now.Day, _absenSetting.Pulang.Hours,
                                          _absenSetting.Pulang.Minutes, _absenSetting.Pulang.Seconds);


                var nowSearch = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

                var absenToday = _db.Absens.Where(x => x.KaryawanId == karyawanId && x.Masuk.Value.Year == nowSearch.Year &&
                                                  x.Masuk.Value.Month == nowSearch.Month && x.Masuk.Value.Day == nowSearch.Day).FirstOrDefault();
                if (absenToday == null)
                {
                    //Absen Masuk
                    if (now.TimeOfDay > masuk.TimeOfDay)
                    {
                        if (!_absenSetting.Konpensasi)
                        {
                            throw new SystemException("Maaf Anda Terlambat !");
                        }
                        else
                        {
                            var konpensasi = masuk.Add(_absenSetting.KonpensasiMasuk);
                            if (now.TimeOfDay > konpensasi.TimeOfDay)
                            {
                                throw new SystemException("Maaf Anda Terlambat !");
                            }
                        }
                    }
                    absenToday = new Absen {
                        KaryawanId = karyawanId, Masuk = now
                    };
                    _db.Absens.Add(absenToday);
                }
                else
                {
                    //absen pulang
                    if (absenToday.Pulang != null)
                    {
                        throw new SystemException("Anda Sudah Absen Pulang Hari Ini !");
                    }

                    if (now.TimeOfDay < pulang.TimeOfDay)
                    {
                        if (!_absenSetting.Konpensasi)
                        {
                            throw new SystemException("Maaf Anda Belum Saatnya Pulang !");
                        }
                        else
                        {
                            var konpensasi = pulang.Subtract(_absenSetting.KonpensasiPulang);
                            if (now.TimeOfDay < konpensasi.TimeOfDay)
                            {
                                throw new SystemException("Maaf, Belum Saatnya Anda Pulang !");
                            }
                        }
                    }
                    absenToday.Pulang = now;
                    _db.Absens.Update(absenToday);
                }

                _db.SaveChanges();
                return(absenToday);
            }
            catch (Exception ex)
            {
                throw new SystemException(ex.Message);
            }
        }