protected async Task Add() { try { var detailModel = await Service.Add(new AddDetailModel() { MenuId = SubMenuItemId, Name = Name }, Token); if (detailModel == null) { GlobalMsg.SetMessage("Failed to save", MessageLevel.Error); } else { // workaround to refresh data await Filter(); GlobalMsg.SetMessage("New line added", MessageLevel.Normal); } } catch (AccessTokenNotAvailableException exception) { exception.Redirect(); } catch (System.Exception ex) { GlobalMsg.SetMessage(ex.Message, MessageLevel.Error); } }
protected async Task LoadFile(IFileListEntry file) { if (!file.Type.Contains("image")) { GlobalMsg.SetMessage("Please upload image file(.png or .jpg).", MessageLevel.Error); return; } ; if (file.Size > 1000000) { GlobalMsg.SetMessage("File should be smaller than 1M.", MessageLevel.Error); return; } ; file.OnDataRead += (sender, eventArgs) => InvokeAsync(StateHasChanged); var model = new UploadProductLinkModel() { Id = Item.Id, Image = file.Data, ImageName = file.Name }; var imageUrl = await Service.PostImage(model, Token); if (imageUrl != null) { // show the image Item.Image = imageUrl; GlobalMsg.SetMessage("The file is uploaded.", MessageLevel.Normal); } else { GlobalMsg.SetMessage("Failed to upload the file.", MessageLevel.Error); } }
public MainForm(EvLoop b) { InitializeComponent(); //font PrivateFontCollection fontCollection = new PrivateFontCollection(); fontCollection.AddFontFile("font.ttf"); // файл шрифта FontFamily family = fontCollection.Families[0]; // Создаём шрифт и используем далее Font font = new Font(family, 20); //задача шрифтов ChatLog.Font = font; MsgEnterBox.Font = font; OnlineLable.Font = font; OnlineUsers.Font = font; SendButton.Font = font; this.FormClosing += MainForm_FormClosing; Loop = b; Loop.SetFormAddress(this); ErrorDelegate = new Error(ErrorMethod); GlobalMsgDelegate = new GlobalMsg(GlobalMsgMethod); RefreshOnlineUsersDelegate = new RefreshOnlineUsers(RefreshOnlineUsersMethod); this.Hide(); }
protected async Task LoadFile(IFileListEntry file) { file.OnDataRead += (sender, eventArgs) => InvokeAsync(StateHasChanged); var model = new UploadProductLinkModel() { ProductId = Item.Id, Image = file.Data, ImageName = file.Name }; string imageUrl = await ProductLinkService.PostProductLinkAsync(model); if (imageUrl != null) { Item.ProductLinks.Insert(0, new ProductLinkModel() { ProductId = model.ProductId, Address = imageUrl }); GlobalMsg.SetMessage("File " + file.Name + " uploaded.", MessageLevel.Normal); } else { GlobalMsg.SetMessage("Failed to connect API.", MessageLevel.Error); } }
protected override async Task OnInitializedAsync() { var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); UserEmail = authState.User.Identity.Name; GlobalMsg.SetMessage(); ProductModels = await service.GetProductsAsync(0, 20, ""); }
protected async Task Change(ChangeEventArgs e, PatchUpdateItem patchUpdateItem) { var val = e.Value.ToString(); var isDone = await ProductService.UpdateAsync(Item.Id, val, patchUpdateItem); if (!isDone) { GlobalMsg.SetMessage("Failed to change the name"); } }
async Task LoadProducts(int page = 1, int quantityPerPage = 10) { try { PageDataModel = await service.GetProductsAsync(page, quantityPerPage, nameFilter, categoryId, token); } catch (System.Exception ex) { GlobalMsg.SetMessage(ex.Message, MessageLevel.Error); } }
protected override async Task OnInitializedAsync() { var tokenResult = await AuthenticationService.RequestAccessToken(); tokenResult.TryGetToken(out var tokenReference); Token = tokenReference.Value; //var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); //UserEmail = authState.User.Identity.Name; GlobalMsg.SetMessage(); }
protected async Task LoadFile(IFileListEntry file) { file.OnDataRead += (sender, eventArgs) => InvokeAsync(StateHasChanged); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/uploads", file.Name); var model = new ProductLinkModel() { Address = file.Name, Type = file.Type, ProductId = Item.Id }; /* * var endpoint = "<yourEndpoint>"; * var accessKeyId = "<yourAccessKeyId>"; * var accessKeySecret = "<yourAccessKeySecret>"; * var bucketName = "<yourBucketName>"; * var objectName = "<yourObjectName>"; * var objectContent = "More than just cloud."; * // Create an OSSClient instance. * var client = new OssClient(endpoint, accessKeyId, accessKeySecret); * try * { * byte[] binaryData = Encoding.ASCII.GetBytes(objectContent); * MemoryStream requestContent = new MemoryStream(5); * // Upload a file. * client.PutObject(bucketName, objectName, requestContent); * Console.WriteLine("Put object succeeded"); * } * catch (Exception ex) * { * Console.WriteLine("Put object failed, {0}", ex.Message); * } */ if (await ProductLinkService.PostProductLinkAsync(model) != null) { using (var stream = new FileStream(path, FileMode.Create)) { var ms = new MemoryStream(); await file.Data.CopyToAsync(stream); } Item.ProductLinks.Add(model); GlobalMsg.SetMessage("File " + file.Name + " uploaded.", MessageLevel.Error); } else { GlobalMsg.SetMessage("Failed to connect API.", MessageLevel.Error); } }
async Task LoadDetails(int page = 1, int quantityPerPage = 10) { try { PageDataModel = await Service.GetSubItemDetailAsync(SubMenuItemId.ToString(), page, quantityPerPage, title, Token); } catch (AccessTokenNotAvailableException exception) { exception.Redirect(); } catch (System.Exception ex) { GlobalMsg.SetMessage(ex.Message, MessageLevel.Error); } }
async Task LoadTabs() { try { TabsModel = await Service.GetAll <SubMenuItemModel>(SubSystemId, Token); var one = TabsModel.FirstOrDefault(); if (one != null) { one.TabHeader = "active"; one.TabDetail = "show active"; one.TabHeaderSelect = "true"; } } catch (AccessTokenNotAvailableException exception) { exception.Redirect(); } catch (Exception ex) { GlobalMsg.SetMessage(ex.Message, MessageLevel.Error); } }
protected async Task Change(ChangeEventArgs e, PatchUpdateItem patchUpdateItem) { var val = e.Value.ToString(); PatchUpdate[] patchUpdates = new PatchUpdate[1]; if (patchUpdateItem == PatchUpdateItem.Title) { patchUpdates[0] = new PatchUpdate { op = "replace", path = "Title", value = val }; Item.Title = val; } if (patchUpdateItem == PatchUpdateItem.Paragraph) { patchUpdates[0] = new PatchUpdate { op = "replace", path = "Paragraph", value = val }; } if (patchUpdateItem == PatchUpdateItem.Order) { patchUpdates[0] = new PatchUpdate { op = "replace", path = "Order", value = val }; } if (patchUpdateItem == PatchUpdateItem.Disabled) { patchUpdates[0] = new PatchUpdate { op = "replace", path = "Disabled", value = val }; } var isDone = await Service.UpdateAsync(Item.Id, val, patchUpdates); if (!isDone) { GlobalMsg.SetMessage("Failed to change the name"); } }