Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using BI.Elic.Web.Models;
- using BI.Elic.Web.Models.Dto;
- using BI.Elic.Web.Modules.DataAnnotations;
- using BI.Elic.Web.Modules.Security;
- using BI.Elic.Web.Service.IService;
- using DevExtreme.AspNet.Data.ResponseModel;
- using DevExtreme.AspNet.Mvc;
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json;
- using System.Collections.Generic;
- using System.Net;
- using System.Reflection;
- namespace BI.Elic.Web.Controllers
- {
- // [AuthorizeController()]
- public class AdminKonsultasiPCMController : BaseController
- {
- private readonly IMasterAPIService _konsultasiPCMService;
- private readonly IAdminAPIService _AdminAPIService;
- public AdminKonsultasiPCMController(IMasterAPIService konsultasiPCMService, IAdminAPIService AdminAPIService)
- {
- _konsultasiPCMService = konsultasiPCMService;
- _AdminAPIService = AdminAPIService;
- }
- // [NeedIndexActionPermission()]
- public async Task<IActionResult> Index()
- {
- ViewBag.HasAddPermission = this.HasControllerActionPermission(ActionPermissionKind.Add);
- ViewBag.HasDeletePermission = this.HasControllerActionPermission(ActionPermissionKind.Delete);
- ViewBag.HasEditPermission = this.HasControllerActionPermission(ActionPermissionKind.Edit);
- return View();
- }
- // [NeedAddActionPermission()]
- public async Task<IActionResult> PilihJadwal()
- {
- ViewBag.AddResult = null;
- return View();
- }
- // [NeedAddActionPermission()]
- public async Task<IActionResult> Add(int id)
- {
- ViewBag.pcmcmid = id;
- ViewBag.AddResult = null;
- return View();
- }
- // [NeedAddActionPermission()]
- [HttpPost]
- public async Task<ApiResponse?> Save([FromBody] ViewKonsultasiPCMDto model)
- {
- ViewBag.AddResult = null;
- if (ModelState.IsValid)
- {
- ApiResponse? response = await _konsultasiPCMService.SaveAdminKonsultasiPCMAsync(model);
- if (response != null && response.status)
- {
- //ViewBag.AddResult = response;
- return response;
- }
- }
- return null;
- }
- [HttpPost]
- public async Task<IActionResult> Reschedule([FromBody] ViewKonsultasiPCMDto model)
- {
- ViewBag.AddResult = null;
- if (ModelState.IsValid)
- {
- ApiResponse? response = await _konsultasiPCMService.RescheduleAdminKonsultasiPCMAsync(model);
- if (response != null && response.status)
- {
- ViewBag.AddResult = response;
- return View(model);
- }
- }
- return View(model);
- }
- public async Task<IActionResult> GetJadwalKonsultasiPCM(DataSourceLoadOptions loadOptions)
- {
- List<AdminTimePCMCMDto>? list = new();
- ApiResponse? response = await _AdminAPIService.GetJadwalKonsultasiPCMAsync();
- if (response != null && response.status)
- {
- list = JsonConvert.DeserializeObject<List<AdminTimePCMCMDto>>(Convert.ToString(response.data));
- }
- return Json(list);
- }
- public async Task<IActionResult> ResponseKonsultasi(int id)
- {
- if (id == 0)
- {
- return StatusCode((int)HttpStatusCode.BadRequest);
- }
- ViewKonsultasiPCMDto? obj = new();
- ApiResponse? response = await _konsultasiPCMService.GetAdminKonsultasiPCMByIdAsync(id);
- if (response != null && response.status)
- {
- obj = JsonConvert.DeserializeObject<ViewKonsultasiPCMDto>(Convert.ToString(response.data));
- }
- ViewBag.EditResult = null;
- return View(obj);
- }
- [HttpPost]
- public async Task<IActionResult> UploadFile(IFormFile fileDokumen, string namaDokumen)
- {
- if (fileDokumen != null && fileDokumen.Length > 0)
- {
- using (var memoryStream = new MemoryStream())
- {
- await fileDokumen.CopyToAsync(memoryStream);
- var fileData = memoryStream.ToArray();
- var fileInfo = new
- {
- namaDokumen = namaDokumen,
- namaFile = fileDokumen.FileName,
- dateCreatedDocument = DateTime.Now.ToString("yyyy-MM-dd"),
- contentType = fileDokumen.ContentType,
- fileData = Convert.ToBase64String(fileData)
- };
- // Simpan file ke server atau database jika diperlukan
- return Json(new { success = true, fileInfo = fileInfo });
- }
- }
- return Json(new { success = false, message = "File upload failed." });
- }
- [HttpPost]
- public async Task<IActionResult> Edit([FromBody] ViewKonsultasiPCMDto model)
- {
- ViewBag.EditResult = null;
- if (ModelState.IsValid)
- {
- ApiResponse? response = await _konsultasiPCMService.UpdateKonsultasiPCMAsync(model);
- if (response != null && response.status)
- {
- ViewBag.EditResult = response;
- return View(model);
- }
- }
- return View(model);
- }
- [HttpPost]
- public void Delete(int key)
- {
- SafeExecute(async () =>
- {
- PemohonKonsultasiPCMDto? obj = new();
- //ApiResponse? oldData = await _konsultasiPCMService.GetKonsultasiPCMByIdAsync(key);
- ApiResponse? response = await _konsultasiPCMService.DeleteKonsultasiPCMAsync(key);
- if (response != null && response.status)
- {
- obj = JsonConvert.DeserializeObject<PemohonKonsultasiPCMDto>(Convert.ToString(response.data));
- }
- });
- }
- public async Task<IActionResult> GetDSPKonsultasiPCM()
- {
- List<ViewKonsultasiPCMDto>? list = new();
- ApiResponse? response = await _konsultasiPCMService.GetAdminKonsultasiPCMAsync();
- if (response != null && response.status)
- {
- list = JsonConvert.DeserializeObject<List<ViewKonsultasiPCMDto>>(Convert.ToString(response.data));
- }
- return Json(list);
- }
- }
- }
Add Comment
Please, Sign In to add comment