0rx

FECX

0rx
Oct 14th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.71 KB | None | 0 0
  1. using BI.Elic.Web.Models;
  2. using BI.Elic.Web.Models.Dto;
  3. using BI.Elic.Web.Modules.DataAnnotations;
  4. using BI.Elic.Web.Modules.Security;
  5. using BI.Elic.Web.Service.IService;
  6. using DevExtreme.AspNet.Data.ResponseModel;
  7. using DevExtreme.AspNet.Mvc;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Newtonsoft.Json;
  10. using System.Collections.Generic;
  11. using System.Net;
  12. using System.Reflection;
  13.  
  14. namespace BI.Elic.Web.Controllers
  15. {
  16.     // [AuthorizeController()]
  17.     public class AdminKonsultasiPCMController : BaseController
  18.     {
  19.         private readonly IMasterAPIService _konsultasiPCMService;
  20.  
  21.         private readonly IAdminAPIService _AdminAPIService;
  22.         public AdminKonsultasiPCMController(IMasterAPIService konsultasiPCMService, IAdminAPIService AdminAPIService)
  23.         {
  24.             _konsultasiPCMService = konsultasiPCMService;
  25.             _AdminAPIService = AdminAPIService;
  26.         }
  27.  
  28.  
  29.         // [NeedIndexActionPermission()]
  30.         public async Task<IActionResult> Index()
  31.         {
  32.             ViewBag.HasAddPermission = this.HasControllerActionPermission(ActionPermissionKind.Add);
  33.             ViewBag.HasDeletePermission = this.HasControllerActionPermission(ActionPermissionKind.Delete);
  34.             ViewBag.HasEditPermission = this.HasControllerActionPermission(ActionPermissionKind.Edit);
  35.  
  36.             return View();
  37.         }
  38.  
  39.         //   [NeedAddActionPermission()]
  40.         public async Task<IActionResult> PilihJadwal()
  41.         {
  42.             ViewBag.AddResult = null;
  43.             return View();
  44.         }
  45.         //   [NeedAddActionPermission()]
  46.         public async Task<IActionResult> Add(int id)
  47.         {
  48.             ViewBag.pcmcmid = id;
  49.             ViewBag.AddResult = null;
  50.             return View();
  51.         }
  52.         //   [NeedAddActionPermission()]
  53.         [HttpPost]
  54.         public async Task<ApiResponse?> Save([FromBody] ViewKonsultasiPCMDto model)
  55.         {
  56.             ViewBag.AddResult = null;
  57.             if (ModelState.IsValid)
  58.             {
  59.                 ApiResponse? response = await _konsultasiPCMService.SaveAdminKonsultasiPCMAsync(model);
  60.                 if (response != null && response.status)
  61.                 {
  62.                     //ViewBag.AddResult = response;
  63.                     return response;
  64.                 }
  65.             }
  66.             return null;
  67.         }
  68.        
  69.         [HttpPost]
  70.         public async Task<IActionResult> Reschedule([FromBody] ViewKonsultasiPCMDto model)
  71.         {
  72.             ViewBag.AddResult = null;
  73.             if (ModelState.IsValid)
  74.             {
  75.                 ApiResponse? response = await _konsultasiPCMService.RescheduleAdminKonsultasiPCMAsync(model);
  76.                 if (response != null && response.status)
  77.                 {
  78.                     ViewBag.AddResult = response;
  79.                     return View(model);
  80.                 }
  81.             }
  82.  
  83.             return View(model);
  84.         }
  85.  
  86.         public async Task<IActionResult> GetJadwalKonsultasiPCM(DataSourceLoadOptions loadOptions)
  87.         {
  88.             List<AdminTimePCMCMDto>? list = new();
  89.  
  90.             ApiResponse? response = await _AdminAPIService.GetJadwalKonsultasiPCMAsync();
  91.             if (response != null && response.status)
  92.             {
  93.                 list = JsonConvert.DeserializeObject<List<AdminTimePCMCMDto>>(Convert.ToString(response.data));
  94.             }
  95.             return Json(list);
  96.         }
  97.  
  98.  
  99.         public async Task<IActionResult> ResponseKonsultasi(int id)
  100.         {
  101.             if (id == 0)
  102.             {
  103.                 return StatusCode((int)HttpStatusCode.BadRequest);
  104.             }
  105.  
  106.             ViewKonsultasiPCMDto? obj = new();
  107.             ApiResponse? response = await _konsultasiPCMService.GetAdminKonsultasiPCMByIdAsync(id);
  108.             if (response != null && response.status)
  109.             {
  110.                 obj = JsonConvert.DeserializeObject<ViewKonsultasiPCMDto>(Convert.ToString(response.data));
  111.             }
  112.             ViewBag.EditResult = null;
  113.             return View(obj);
  114.         }
  115.  
  116.         [HttpPost]
  117.         public async Task<IActionResult> UploadFile(IFormFile fileDokumen, string namaDokumen)
  118.         {
  119.             if (fileDokumen != null && fileDokumen.Length > 0)
  120.             {
  121.                 using (var memoryStream = new MemoryStream())
  122.                 {
  123.                     await fileDokumen.CopyToAsync(memoryStream);
  124.                     var fileData = memoryStream.ToArray();
  125.                     var fileInfo = new
  126.                     {
  127.                         namaDokumen = namaDokumen,
  128.                         namaFile = fileDokumen.FileName,
  129.                         dateCreatedDocument = DateTime.Now.ToString("yyyy-MM-dd"),
  130.                         contentType = fileDokumen.ContentType,
  131.                         fileData = Convert.ToBase64String(fileData)
  132.                     };
  133.  
  134.                     // Simpan file ke server atau database jika diperlukan
  135.  
  136.                     return Json(new { success = true, fileInfo = fileInfo });
  137.                 }
  138.             }
  139.  
  140.             return Json(new { success = false, message = "File upload failed." });
  141.         }
  142.  
  143.  
  144.         [HttpPost]
  145.         public async Task<IActionResult> Edit([FromBody] ViewKonsultasiPCMDto model)
  146.         {
  147.             ViewBag.EditResult = null;
  148.             if (ModelState.IsValid)
  149.             {
  150.                 ApiResponse? response = await _konsultasiPCMService.UpdateKonsultasiPCMAsync(model);
  151.                 if (response != null && response.status)
  152.                 {
  153.                     ViewBag.EditResult = response;
  154.                     return View(model);
  155.                 }
  156.             }
  157.  
  158.             return View(model);
  159.         }
  160.  
  161.         [HttpPost]
  162.         public void Delete(int key)
  163.         {
  164.             SafeExecute(async () =>
  165.             {
  166.                 PemohonKonsultasiPCMDto? obj = new();
  167.  
  168.                 //ApiResponse? oldData = await _konsultasiPCMService.GetKonsultasiPCMByIdAsync(key);
  169.                 ApiResponse? response = await _konsultasiPCMService.DeleteKonsultasiPCMAsync(key);
  170.                 if (response != null && response.status)
  171.                 {
  172.                     obj = JsonConvert.DeserializeObject<PemohonKonsultasiPCMDto>(Convert.ToString(response.data));
  173.                 }
  174.  
  175.             });
  176.         }
  177.  
  178.         public async Task<IActionResult> GetDSPKonsultasiPCM()
  179.         {
  180.             List<ViewKonsultasiPCMDto>? list = new();
  181.  
  182.             ApiResponse? response = await _konsultasiPCMService.GetAdminKonsultasiPCMAsync();
  183.             if (response != null && response.status)
  184.             {
  185.                 list = JsonConvert.DeserializeObject<List<ViewKonsultasiPCMDto>>(Convert.ToString(response.data));
  186.             }
  187.             return Json(list);
  188.         }
  189.  
  190.     }
  191. }
  192.  
Add Comment
Please, Sign In to add comment