示例#1
0
        public async Task <IActionResult> Pemenang([FromBody] Pemenang pemenang)
        {
            try
            {
                _context.Pemenang.Add(pemenang);
                var result = _context.SaveChanges();
                if (result <= 0)
                {
                    throw new SystemException("Pemenang Tidak Berhasil Disimpan");
                }
                var karyawan = _context.Karyawan.Where(x => x.Id == pemenang.KaryawanId).FirstOrDefault();
                if (karyawan != null)
                {
                    var message = new NotificationModel("System", "Undian",
                                                        $"Pemenang Undian Peride Ini '{karyawan.NamaKaryawan}'", NotificationType.Public);

                    var message1 = new NotificationModel("System", "Undian",
                                                         $"Anda Adalah Pemeang Undian Periode Ini", NotificationType.Private);
                    message1.UserId = karyawan.UserId;

                    await _fmc.SendMessage(message, "all");

                    await _fmc.SendMessagePrivate(message1, karyawan.DeviceId);
                }
                return(Ok(true));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#2
0
        public async Task <IActionResult> GetAsync()
        {
            try
            {
                var actived = await _periode.ActivePeriode();

                if (actived == null)
                {
                    throw new SystemException("Periode Aktif Belum Ditemukan");
                }
                var pelanggarans = _context.Pelanggaran.Where(x => x.Tanggal >= actived.Mulai && x.Tanggal <= actived.Selesai)
                                   .Include(x => x.ItemPelanggarans).ThenInclude(x => x.DetailLevel).ThenInclude(x => x.Level)
                                   .Include(x => x.Perusahaan);
                var a              = pelanggarans.SelectMany(x => x.ItemPelanggarans);
                var perusahaan     = pelanggarans.ToList().GroupBy(x => x.PerusahaanId);
                var dataperusahaan = new List <dynamic>();
                foreach (var item in perusahaan)
                {
                    var dataitem = item.FirstOrDefault();
                    dataperusahaan.Add(new
                    {
                        namaperusahaan = dataitem.Perusahaan.Nama,
                        total          = item.Count()
                    });
                }

                var datas = new List <dynamic>();
                var group = a.ToList().GroupBy(x => x.DetailLevel.LevelId).ToList();
                foreach (var items in group)
                {
                    var dataTemp = items.FirstOrDefault();

                    dynamic data = new
                    {
                        LevelId          = dataTemp.DetailLevel.LevelId,
                        Jenispelanggaran = dataTemp.DetailLevel.Nama,
                        Perusahaan       = dataTemp.NilaiPerusahaan,
                        Karyawan         = items.Count(),
                        // Tanggal = dataTemp.,
                        Level = dataTemp.DetailLevel.Level.Nama,
                        Today = pelanggarans.Where(x => x.Tanggal.Year == DateTime.Now.Year && x.Tanggal.Month == DateTime.Now.Month &&
                                                   x.Tanggal.Day == DateTime.Now.Day).Count()
                    };
                    datas.Add(data);
                }

                var karyawan = _context.Karyawan.Find(1);
                if (karyawan != null)
                {
                    var notif = new NotificationModel {
                        Body    = "Body Message", Title = "Titale", NotificationType = NotificationType.Private,
                        Created = DateTime.Now, Sender = "HRD", UserId = karyawan.UserId, Id = 0
                    };
                    notif.UserId = karyawan.UserId;
                    await _fcm.SendMessagePrivate(notif, karyawan.DeviceId);

                    notif.UserId           = string.Empty;
                    notif.NotificationType = NotificationType.Public;
                    await _fcm.SendMessage(notif, "all");
                }

                return(Ok(new { datas = datas.ToList(), perusahaan = dataperusahaan }));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }