예제 #1
0
        public async Task <IActionResult> Upsert(int?id)
        {
            IEnumerable <TimeSheet> timeSheetList = await _timeSheetRepository.GetAllAsync(SD.TimeSheetAPIPath, HttpContext.Session.GetString("JWToken"));

            AuditFileViewModel objVM = new AuditFileViewModel()
            {
                TimeSheetList = timeSheetList.Select(i => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
                {
                    Text  = i.Type,
                    Value = i.Id.ToString()
                }),
                AuditFile = new AuditFile()
            };

            if (id == null)
            {
                return(View(objVM));
            }

            objVM.AuditFile = await _auditFileRepository.GetAsync(SD.AuditFilePath, id.GetValueOrDefault(), HttpContext.Session.GetString("JWToken"));

            if (objVM.AuditFile == null)
            {
                return(NotFound());
            }
            return(View(objVM));
        }
예제 #2
0
 public async Task <IActionResult> Upsert(AuditFileViewModel obj)
 {
     if (ModelState.IsValid)
     {
         if (obj.AuditFile.Id == 0)
         {
             await _auditFileRepository.CreateAsync(SD.AuditFilePath, obj.AuditFile, HttpContext.Session.GetString("JWToken"));
         }
         else
         {
             await _auditFileRepository.UpdateAsync(SD.AuditFilePath + obj.AuditFile.Id, obj.AuditFile, HttpContext.Session.GetString("JWToken"));
         }
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View(obj));
     }
 }