protected async Task HandleFormSubmit() { var result = await ResourceService.CreateResource(Resource); if (result != null) { ToastService.ShowSuccess($"Resursas '{Resource.Name}' yra sėkmingai sukurtas"); NavigationManager.NavigateTo("/resources"); } else { ToastService.ShowError("Nepavyko sukurti resurso"); } }
public ActionResult CreateResources(CreateResourcesViewModel model) { var resource = model.GetResourceFromModel(); var result = _resourcesService.CreateResource(resource); var jsonMessage = new SimpleJsonMessageViewModel(); if (result.IsOK) { jsonMessage.IsOk = true; jsonMessage.Message = "Успешно креиран ресурс!"; jsonMessage.Data = new ResourceViewModel(result.GetData()); return(Json(jsonMessage)); } else { jsonMessage.IsOk = false; jsonMessage.Message = "Неуспешно креран ресурс. Обиди се повторно!"; return(Json(jsonMessage)); } }
public Response CreateResource([FromBody] ResourceModel resourceModel) { Response reqResponse = new Response(); int userId = _userService.GetUser(resourceModel.username, resourceModel.password); if (userId == -1) { reqResponse.SetResponse(401, "Not Authorized", "Invalid credentials inserted!", null); goto Finish; } ResourcePathModel resourceInfo = new ResourcePathModel(resourceModel.resourceName); if (!_resourceService.IsPathValid(resourceInfo.resourcePath)) { reqResponse.SetResponse(404, "Not Existing", resourceInfo.resourcePath + " does not exist in the current filesystem.", null); goto Finish; } if (!_resourceService.IsUserOwner(resourceInfo.resourcePath, userId)) { reqResponse.SetResponse(401, "Not Authorized", "You do not have the rights to access this resource. Please contact the owner of the selected resource.", null); goto Finish; } if (_resourceService.ResourceExists(resourceInfo.fullResourcePath)) { reqResponse.SetResponse(500, "Already Existing", resourceInfo.fullResourcePath + " already exists in the current filesystem.", null); goto Finish; } _resourceService.CreateResource(resourceInfo.resourceName, resourceInfo.fullResourcePath, resourceInfo.resourcePath, userId, resourceModel.resourceTypeId, resourceModel.value); reqResponse = new Response(); Finish: return(reqResponse); }