public IActionResult Details(int id) { var systemDetails = _systemService.Get(id); SystemDetailsViewModel systemDetailsViewModel = new SystemDetailsViewModel() { Id = systemDetails.Id, Name = systemDetails.Name, Description = systemDetails.Description, }; return(View(systemDetailsViewModel)); }
public async Task <IActionResult> AddInventoryObjectSystemAjaxFormAsync(SystemDetailsViewModel toAddModel) { if (!ModelState.IsValid) { ModelState.AddModelError(string.Empty, "Податоците не се валидни"); return(PartialView("FormModals/_AddSystemFormPartial", toAddModel)); } // the client could validate this, but allowed for testing server errors if (toAddModel.Name.Length < 3) { ModelState.AddModelError(string.Empty, "Name should be longer than 2 chars"); return(PartialView("FormModals/_AddSystemFormPartial", toAddModel)); } var httpClient = await _facilityManagementHttpClient.GetClient(); var serializedUpdatedModel = JsonConvert.SerializeObject(toAddModel); StringContent content = new StringContent(serializedUpdatedModel, Encoding.Unicode, "application/json"); var response = await httpClient.PostAsync($"api/inventory/systems", content).ConfigureAwait(false); if (response.IsSuccessStatusCode) { bool isAjaxRequest = Request.Headers["X-Requested-With"] == "XMLHttpRequest"; if (isAjaxRequest) { return(Content("success")); } else { return(RedirectToAction("Index", "InventoryObjects")); } } else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized || response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { return(RedirectToAction("AccessDenied", "Authorization")); } throw new Exception($"A problem happened while calling the API: {response.ReasonPhrase}"); }