public async Task <UpdateUphSdmResponse> Handle(UpdateUphSdmRequest request, CancellationToken cancellationToken) { var result = new UpdateUphSdmResponse(); var entity = await _context.UphSdms .FirstOrDefaultAsync(x => x.UphSdmID == request.UphSdmID, cancellationToken); entity.UphSdmID = request.UphSdmID; entity.UphID = request.UphID; entity.jml_sdm = request.jml_sdm; entity.struktur_modal = request.struktur_modal; entity.sop = string.Join(",", request.sops); entity.sumber_modal = string.Join(",", request.sumber_modals); entity.jml_modal = request.sumber_modals.Count().ToString(); entity.nama_pelatihan = request.nama_pelatihan; entity.penyelenggara = request.penyelenggara; entity.lokasi = request.lokasi; entity.tahun = request.tahun; await _context.SaveChangesAsync(cancellationToken); result.UphSdmID = entity.UphSdmID; return(result); }
public async Task <UpdateUphProduksiResponse> Handle(UpdateUphProduksiRequest request, CancellationToken cancellationToken) { var result = new UpdateUphProduksiResponse(); var entity = await _context.UphProduksis .FirstOrDefaultAsync(x => x.UphProduksiID == request.UphProduksiID, cancellationToken); entity.UphProduksiID = request.UphProduksiID; entity.UphID = request.UphID; entity.sertifikat = string.Join(",", request.sertifikats); entity.jml_sertifikat = request.sertifikats.Count().ToString(); entity.bahan_baku = request.bahan_baku; entity.jml_produksi = request.jml_produksi; entity.satuan = request.satuan; entity.jml_hari_produksi = request.jml_hari_produksi; entity.izin_edar = request.izin_edar; await _context.SaveChangesAsync(cancellationToken); result.UphProduksiID = entity.UphProduksiID; return(result); }
public async Task <ResetPasswordResponse> Handle(ResetPasswordRequest request, CancellationToken cancellationToken) { var result = new ResetPasswordResponse(); var user = await _context.Users.FindAsync(request.UserID); if (user != null) { string passwordSalt; string passwordHash; if (!string.IsNullOrEmpty(request.Password)) { if (!AppUtility.VerifyPasswordHash(request.Password, user.PasswordSalt, user.PasswordHash)) { passwordSalt = AppUtility.CreatePasswordSalt(); passwordHash = AppUtility.CreatePasswordHash(request.Password, passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; } } await _context.SaveChangesAsync(cancellationToken); } else { throw new Exception("Maaf, User tidak ditemukan"); } return(result); }
public async Task <SeedAsalBantuanResponse> Handle(SeedAsalBantuanRequest request, CancellationToken cancellationToken) { var result = new SeedAsalBantuanResponse(); var dataJSON = _fileService.ReadJSONFile <AsalBantuanJSON>(FilePath.AsalBantuanJSON); List <AsalBantuan> asalBantuans = new List <AsalBantuan>(); var listDataJSON = dataJSON.rows.ToList(); foreach (var data in listDataJSON) { AsalBantuan asalBantuan = new AsalBantuan(); asalBantuan = asalBantuans .SingleOrDefault(x => x.AsalBantuanID == data.id_asal_bantuan); if (asalBantuan == null) { asalBantuan = new AsalBantuan { Name = data.nama_asal_bantuan }; asalBantuans.Add(asalBantuan); _context.AsalBantuans.Add(asalBantuan); } } await _context.SaveChangesAsync(cancellationToken); return(result); }
public async Task <UpdateUphProdukResponse> Handle(UpdateUphProdukRequest request, CancellationToken cancellationToken) { var result = new UpdateUphProdukResponse(); var uphProduk = await _context.UphProduks.FirstOrDefaultAsync(x => x.UphProdukID == request.UphProdukID, cancellationToken); if (request.Name != uphProduk.Name) { if (await _context.UphProduks.AnyAsync(x => x.UphID == request.UphID && x.Name == request.Name)) { throw new Exception("Maaf Nama Produk sudah di gunakan di UPH ini"); } } if (uphProduk != null) { uphProduk.UphID = request.UphID; uphProduk.JenisTernakID = request.JenisTernakID; uphProduk.ProdukOlahanID = request.ProdukOlahanID; uphProduk.SatuanID = request.SatuanID; uphProduk.Name = request.Name; uphProduk.Berat = request.Berat; uphProduk.Harga = request.Harga; uphProduk.Description = request.Description; await _context.SaveChangesAsync(cancellationToken); } result.UphProdukID = uphProduk.UphProdukID; return(result); }
public async Task <DeleteUphProdukResponse> Handle(DeleteUphProdukRequest request, CancellationToken cancellationToken) { var result = new DeleteUphProdukResponse(); if (request.UphProdukIDs.Count > 0) { foreach (var item in request.UphProdukIDs) { var entity = await _context.UphProduks.FirstOrDefaultAsync(x => x.UphProdukID == item, cancellationToken); if (entity != null) { // delete file uph produk var file = await _context.Files.AsNoTracking() .Where(x => x.EntityID == entity.UphProdukID && x.EntityType == FileEntityType.UphProduk) .FirstOrDefaultAsync(cancellationToken); await _mediator.Send(new DeleteFileRequest { EntityID = file.EntityID, EntityType = file.EntityType }); // delete uph produk _context.UphProduks.Remove(entity); } } await _context.SaveChangesAsync(cancellationToken); } return(result); }
public async Task <CreateUphBahanBakuResponse> Handle(CreateUphBahanBakuRequest request, CancellationToken cancellationToken) { var result = new CreateUphBahanBakuResponse(); var data = request; var entity = new UphBahanBaku { UphID = data.UphID, id_uph = data.id_uph, id_bahan_baku = data.id_bahan_baku, JenisKomoditiID = data.JenisKomoditiID, JenisTernakID = data.JenisTernakID, SatuanID = data.SatuanID, TotalKebutuhan = data.TotalKebutuhan, AsalBahanBaku = string.Join(",", request.AsalBahanBakus), Nilai = data.Nilai }; await _context.UphBahanBakus.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); result.UphBahanBakuID = entity.UphBahanBakuID; return(result); }
public async Task <UpdateUphSaranaResponse> Handle(UpdateUphSaranaRequest request, CancellationToken cancellationToken) { var result = new UpdateUphSaranaResponse(); var entity = await _context.UphSaranas .FirstOrDefaultAsync(x => x.UphSaranaID == request.UphSaranaID, cancellationToken); entity.UphSaranaID = request.UphSaranaID; entity.UphID = request.UphID; entity.asal_bantuan = string.Join(",", request.asal_bantuans); entity.lain = request.lain; entity.tahun = request.tahun; entity.nama_alat = request.nama_alat; entity.kapasitas_terpakai = request.kapasitas_terpakai; entity.kapasitas_terpasang = request.kapasitas_terpasang; entity.satuan = request.satuan; entity.jenis_mesin = request.jenis_mesin; entity.status = request.status; entity.alasan = string.Join(",", request.alasans); entity.lain_alasan = request.lain_alasan; await _context.SaveChangesAsync(cancellationToken); result.UphSaranaID = entity.UphSaranaID; return(result); }
public async Task <SeedParameterAspekResponse> Handle(SeedParameterAspekRequest request, CancellationToken cancellationToken) { var result = new SeedParameterAspekResponse(); var dataJSON = _fileService.ReadJSONFile <ParameterAspekJSON>(FilePath.ParameterAspekJSON); List <ParameterAspek> parameterAspeks = new List <ParameterAspek>(); var listDataJSON = dataJSON.rows.ToList(); foreach (var data in listDataJSON) { ParameterAspek parameterAspek = new ParameterAspek(); parameterAspek = parameterAspeks .SingleOrDefault(x => x.ParameterAspekID == data.id_aspek); if (parameterAspek == null) { parameterAspek = new ParameterAspek { Name = data.nama_aspek, id_aspek = data.id_aspek }; parameterAspeks.Add(parameterAspek); _context.ParameterAspeks.Add(parameterAspek); } } await _context.SaveChangesAsync(cancellationToken); return(result); }
public async Task <CreateUphProdukResponse> Handle(CreateUphProdukRequest request, CancellationToken cancellationToken) { var result = new CreateUphProdukResponse(); var options = _configuration.GetSection(SiUpinOptions.RootSection).Get <SiUpinOptions>(); if (await _context.UphProduks.AnyAsync(x => x.UphID == request.UphID && x.Name == request.Name)) { throw new Exception("Maaf Nama Produk sudah di gunakan di UPH ini"); } else { var entity = new UphProduk { UphID = request.UphID, JenisTernakID = request.JenisTernakID, ProdukOlahanID = request.ProdukOlahanID, SatuanID = request.SatuanID, Name = request.Name, Berat = request.Berat, Harga = request.Harga, Description = request.Description }; await _context.UphProduks.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); result.UphProdukID = entity.UphProdukID; } return(result); }
public async Task <CreateUphPasarResponse> Handle(CreateUphPasarRequest request, CancellationToken cancellationToken) { var result = new CreateUphPasarResponse(); var entity = new UphPasar { UphID = request.UphID, mekanisme = string.Join(",", request.mekanismes), nilai_mekanisme = request.mekanismes.Count().ToString(), jangkauan = request.jangkauan, jml_penjualan = request.jml_penjualan, omset = request.omset, lain = request.lain }; await _context.UphPasars.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); result.UphPasarID = entity.UphPasarID; return(result); }
public async Task <SeedProvinsiResponse> Handle(SeedProvinsiRequest request, CancellationToken cancellationToken) { var result = new SeedProvinsiResponse(); var dataOld = await _entityRepository.GetAllProvinsi(); List <Provinsi> provinsis = await _context.Provinsis.ToListAsync(cancellationToken); foreach (var data in dataOld) { Provinsi provinsi = new Provinsi(); provinsi = provinsis .SingleOrDefault(x => x.id_provinsi == data.id_provinsi); if (provinsi == null) { provinsi = new Provinsi { id_provinsi = data.id_provinsi, Name = data.nama_provinsi }; provinsis.Add(provinsi); _context.Provinsis.Add(provinsi); } } await _context.SaveChangesAsync(cancellationToken); result.IsSuccessful = true; return(result); }
public async Task <CreateUphSaranaResponse> Handle(CreateUphSaranaRequest request, CancellationToken cancellationToken) { var result = new CreateUphSaranaResponse(); var entity = new UphSarana { UphID = request.UphID, asal_bantuan = string.Join(",", request.asal_bantuans), lain = request.lain, tahun = request.tahun, nama_alat = request.nama_alat, kapasitas_terpakai = request.kapasitas_terpakai, kapasitas_terpasang = request.kapasitas_terpasang, satuan = request.satuan, jenis_mesin = request.jenis_mesin, status = request.status, alasan = string.Join(",", request.alasans), lain_alasan = request.lain_alasan, }; await _context.UphSaranas.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); result.UphSaranaID = entity.UphSaranaID; return(result); }
public async Task <CreateUphSdmResponse> Handle(CreateUphSdmRequest request, CancellationToken cancellationToken) { var result = new CreateUphSdmResponse(); var entity = new UphSdm { UphID = request.UphID, jml_sdm = request.jml_sdm, struktur_modal = request.struktur_modal, sop = string.Join(",", request.sops), sumber_modal = string.Join(",", request.sumber_modals), jml_modal = request.sumber_modals.Count().ToString(), nama_pelatihan = request.nama_pelatihan, penyelenggara = request.penyelenggara, lokasi = request.lokasi, tahun = request.tahun, }; await _context.UphSdms.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); result.UphSdmID = entity.UphSdmID; return(result); }
public async Task <SeedParameterJawabanResponse> Handle(SeedParameterJawabanRequest request, CancellationToken cancellationToken) { var result = new SeedParameterJawabanResponse(); var listOfData = new List <ParameterJawabanExcel>(); // read excel files then add to List var bin = System.IO.File.ReadAllBytes(FilePath.ParameterJawabanExcel); ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using (MemoryStream stream = new MemoryStream(bin)) using (ExcelPackage excelPackage = new ExcelPackage(stream)) { //loop all worksheets foreach (ExcelWorksheet worksheet in excelPackage.Workbook.Worksheets) { //loop all rows for (int i = worksheet.Dimension.Start.Row + 1; i <= worksheet.Dimension.End.Row; i++) { string id_indikator, jawaban, skor = ""; id_indikator = worksheet.Cells[i, 1].Value.ToString(); jawaban = worksheet.Cells[i, 2].Value.ToString(); skor = worksheet.Cells[i, 3].Value.ToString(); listOfData.Add(new ParameterJawabanExcel() { id_indikator = id_indikator, jawaban = jawaban, skor = skor }); } } } // collect provinsi's data from db to temporary List var parentData = await _context.ParameterIndikators .ToListAsync(cancellationToken); foreach (var data in listOfData) { ParameterJawaban ParameterJawaban = new ParameterJawaban(); string parentID = parentData.Where(x => x.id_indikator == data.id_indikator).FirstOrDefault().ParameterIndikatorID ?? ""; ParameterJawaban = new ParameterJawaban { ParameterIndikatorID = parentID, Name = data.jawaban, Skor = data.skor }; _context.ParameterJawabans.Add(ParameterJawaban); } await _context.SaveChangesAsync(cancellationToken); return(result); }
public async Task <CreateUphProduksiResponse> Handle(CreateUphProduksiRequest request, CancellationToken cancellationToken) { var result = new CreateUphProduksiResponse(); var entity = new UphProduksi { UphID = request.UphID, sertifikat = string.Join(",", request.sertifikats), jml_sertifikat = request.sertifikats.Count().ToString(), bahan_baku = request.bahan_baku, jml_produksi = request.jml_produksi, satuan = request.satuan, jml_hari_produksi = request.jml_hari_produksi, izin_edar = request.izin_edar, }; await _context.UphProduksis.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); result.UphProduksiID = entity.UphProduksiID; return(result); }
public async Task <UpdateUserResponse> Handle(UpdateUserRequest request, CancellationToken cancellationToken) { var result = new UpdateUserResponse(); var user = await _context.Users.FindAsync(request.UserID); if (user != null) { string passwordSalt; string passwordHash; if (!string.IsNullOrEmpty(request.Password)) { if (!AppUtility.VerifyPasswordHash(request.Password, user.PasswordSalt, user.PasswordHash)) { passwordSalt = AppUtility.CreatePasswordSalt(); passwordHash = AppUtility.CreatePasswordHash(request.Password, passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; } } if (user.Username != request.Username || user.Email != request.Email) { if (await _context.Users.AsNoTracking().AnyAsync(x => x.Username == request.Username || x.Email == request.Email, cancellationToken)) { throw new Exception("Maaf Username atau Email sudah di gunakan"); } else { user.Username = request.Username; user.Email = request.Email; } } user.Alamat = request.Alamat; user.Fullname = request.Fullname; user.Instansi = request.Instansi; user.Jabatan = request.Jabatan; user.NIP = request.NIP; user.Telepon = request.Telepon; user.RoleID = request.RoleID; user.ProvinsiID = request.ProvinsiID; user.KotaID = request.KotaID; user.KecamatanID = request.KecamatanID; user.KelurahanID = request.KelurahanID; await _context.SaveChangesAsync(cancellationToken); } else { throw new Exception("Maaf, User tidak ditemukan"); } return(result); }
public async Task <DeletePesanResponse> Handle(DeletePesanRequest request, CancellationToken cancellationToken) { var result = new DeletePesanResponse(); var entity = await _context.Pesans.FirstOrDefaultAsync(x => x.PesanID == request.PesanID, cancellationToken); _context.Pesans.Remove(entity); await _context.SaveChangesAsync(cancellationToken); return(result); }
public async Task <UpdateJenisKomoditiResponse> Handle(UpdateJenisKomoditiRequest request, CancellationToken cancellationToken) { var result = new UpdateJenisKomoditiResponse(); var entity = await _context.JenisKomoditis.FirstOrDefaultAsync(x => x.JenisKomoditiID == request.JenisKomoditiID, cancellationToken); entity.Name = request.Name; await _context.SaveChangesAsync(cancellationToken); return(result); }
public async Task <CreateUserResponse> Handle(CreateUserRequest request, CancellationToken cancellationToken) { var result = new CreateUserResponse(); if (!string.IsNullOrEmpty(request.Username)) { if (await _context.Users.AnyAsync(x => x.Username == request.Username)) { throw new Exception("Maaf Username sudah di gunakan"); } } if (!string.IsNullOrEmpty(request.Email)) { if (await _context.Users.AnyAsync(x => x.Email == request.Email, cancellationToken)) { throw new Exception("Maaf Email sudah di gunakan"); } } string passwordSalt = AppUtility.CreatePasswordSalt(); string passwordHash = AppUtility.CreatePasswordHash(request.Password, passwordSalt); var user = new User { Username = request.Username, PasswordHash = passwordHash, PasswordSalt = passwordSalt, Alamat = request.Alamat, Email = request.Email, Fullname = request.Fullname, Instansi = request.Instansi, Jabatan = request.Jabatan, NIP = request.NIP, Telepon = request.Telepon, RoleID = request.RoleID, ProvinsiID = request.ProvinsiID, KotaID = request.KotaID, KecamatanID = request.KecamatanID, KelurahanID = request.KelurahanID }; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(cancellationToken); result.UserID = user.UserID; result.Username = user.Username; return(result); }
public async Task <SeedBeritaResponse> Handle(SeedBeritaRequest request, CancellationToken cancellationToken) { var result = new SeedBeritaResponse(); var dataJSON = _fileService.ReadJSONFile <BeritaJSON>(FilePath.BeritaJSON); List <Berita> beritas = new List <Berita>(); var listDataJSON = dataJSON.rows.ToList(); foreach (var data in listDataJSON) { Berita berita = new Berita(); berita = beritas .SingleOrDefault(x => x.id_berita == data.id_berita); if (berita == null) { berita = new Berita { Title = data.judul, Created = DateTimeOffset.Parse(data.tanggal), Description = data.uraian, id_berita = data.id_berita }; beritas.Add(berita); _context.Beritas.Add(berita); await _context.SaveChangesAsync(cancellationToken); if (!string.IsNullOrEmpty(data.foto)) { await _mediator.Send(new SeedFileRequest() { EntityID = berita.BeritaID, EntityType = "BERITA", Name = data.foto }); } } } result.IsSuccessful = true; return(result); }
public async Task <CreateJenisTernakResponse> Handle(CreateJenisTernakRequest request, CancellationToken cancellationToken) { var result = new CreateJenisTernakResponse(); var entity = new JenisTernak { Name = request.Name }; await _context.JenisTernaks.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); return(result); }
public async Task <UpdateBeritaResponse> Handle(UpdateBeritaRequest request, CancellationToken cancellationToken) { var result = new UpdateBeritaResponse(); var entity = await _context.Beritas.FirstOrDefaultAsync(x => x.BeritaID == request.BeritaID, cancellationToken); entity.Title = request.Title; entity.Description = request.Description; await _context.SaveChangesAsync(cancellationToken); result.BeritaID = entity.BeritaID; return(result); }
public async Task <CreateProdukOlahanResponse> Handle(CreateProdukOlahanRequest request, CancellationToken cancellationToken) { var result = new CreateProdukOlahanResponse(); var entity = new ProdukOlahan { Name = request.Name, JenisKomoditiID = request.JenisKomoditiID }; await _context.ProdukOlahans.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); return(result); }
public async Task <CreatePesanResponse> Handle(CreatePesanRequest request, CancellationToken cancellationToken) { var result = new CreatePesanResponse(); var entity = new Pesan { Name = request.Name, Email = request.Email, Description = request.Description }; await _context.Pesans.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); return(result); }
public async Task <UpdateUphResponse> Handle(UpdateUphRequest request, CancellationToken cancellationToken) { var result = new UpdateUphResponse(); var uph = await _context.Uphs.FirstOrDefaultAsync(x => x.UphID == request.UphID, cancellationToken); if (uph != null) { if (uph.Name != request.Name) { if (await _context.Uphs.AsNoTracking().AnyAsync(x => x.Name == request.Name, cancellationToken)) { throw new Exception("Maaf Nama UPH sudah di gunakan"); } else { uph.Name = request.Name; } } #region uph uph.Name = request.Name; uph.Ketua = request.Ketua; uph.Handphone = request.Handphone; uph.Alamat = request.Alamat; uph.TahunBerdiri = request.TahunBerdiri; uph.ProvinsiID = request.ProvinsiID; uph.KotaID = request.KotaID; uph.KecamatanID = request.KecamatanID; uph.KelurahanID = request.KelurahanID; uph.ParameterBadanHukumID = request.ParameterBadanHukumID; uph.ParameterAdministrasiID = request.ParameterAdministrasiID; uph.ParameterBentukLembagaID = request.ParameterBentukLembagaID; uph.ParameterStatusUphID = request.ParameterStatusUphID; #endregion await _context.SaveChangesAsync(cancellationToken); } else { throw new Exception("Maaf, Uph tidak ditemukan"); } return(result); }
public async Task <DeleteUserResponse> Handle(DeleteUserRequest request, CancellationToken cancellationToken) { var result = new DeleteUserResponse(); var user = await _context.Users.FindAsync(request.UserID); if (user != null) { _context.Users.Remove(user); await _context.SaveChangesAsync(cancellationToken); } else { throw new Exception("Maaf User tidak ditemukan"); } return(result); }
public async Task <UpdateUphGmpResponse> Handle(UpdateUphGmpRequest request, CancellationToken cancellationToken) { var result = new UpdateUphGmpResponse(); var entity = await _context.UphGmps .FirstOrDefaultAsync(x => x.UphGmpID == request.UphGmpID, cancellationToken); entity.UphGmpID = request.UphGmpID; entity.UphID = request.UphID; entity.nama_gmp = string.Join(",", request.nama_gmps); entity.jml_gmp = request.nama_gmps.Count().ToString(); await _context.SaveChangesAsync(cancellationToken); result.UphGmpID = entity.UphGmpID; return(result); }
public async Task <SeedProdukOlahanResponse> Handle(SeedProdukOlahanRequest request, CancellationToken cancellationToken) { var result = new SeedProdukOlahanResponse(); var dataJSON = _fileService.ReadJSONFile <ProdukOlahanJSON>(FilePath.ProdukOlahanJSON); List <ProdukOlahan> produkOlahans = new List <ProdukOlahan>(); var listDataJSON = dataJSON.rows.ToList(); // collect data from db to temporary List var jenisKomoditis = await _context.JenisKomoditis .ToListAsync(cancellationToken); foreach (var data in listDataJSON) { ProdukOlahan produkOlahan = new ProdukOlahan(); produkOlahan = produkOlahans .SingleOrDefault(x => x.ProdukOlahanID == data.id_olahan); if (produkOlahan == null) { string jenisKomoditiID = jenisKomoditis.Where(x => x.id_komoditi == data.id_komoditi_fk).FirstOrDefault().JenisKomoditiID ?? ""; produkOlahan = new ProdukOlahan { id_olahan = data.id_olahan, JenisKomoditiID = jenisKomoditiID, Name = data.nama_olahan }; produkOlahans.Add(produkOlahan); _context.ProdukOlahans.Add(produkOlahan); } } await _context.SaveChangesAsync(cancellationToken); result.IsSuccessful = true; return(result); }
public async Task <CreateBeritaResponse> Handle(CreateBeritaRequest request, CancellationToken cancellationToken) { var result = new CreateBeritaResponse(); var entity = new Berita { Title = request.Title, CreatedBy = request.UserID, Description = request.Description }; await _context.Beritas.AddAsync(entity); await _context.SaveChangesAsync(cancellationToken); result.BeritaID = entity.BeritaID; return(result); }