public async override Task <bool> NewModel(IKntService service) { try { Service = service; var response = await Service.Notes.NewAsync(); Model = response.Entity; // Evaluate whether to put the following default values in the service layer // (null values are by default, we need empty strings so that the IsDirty is // not altered after leaving the view when there are no modifications). Model.Topic = DateTime.Now.ToString(); Model.Tags = ""; Model.Description = ""; Model.ContentType = "markdown"; // Context default values if (FolderWithServiceRef == null) { FolderWithServiceRef = Store.ActiveFolderWithServiceRef; } Model.FolderId = FolderWithServiceRef.FolderInfo.FolderId; Model.FolderDto = FolderWithServiceRef.FolderInfo.GetSimpleDto <FolderDto>(); WindowPostIt = await GetNewWindowPostIt(); Model.SetIsDirty(true); WindowPostIt.SetIsDirty(true); View.RefreshView(); return(await Task.FromResult <bool>(true)); } catch (Exception ex) { View.ShowInfo(ex.Message); } return(await Task.FromResult <bool>(false)); }
public async override Task <bool> LoadModelById(IKntService service, Guid noteId, bool refreshView = true) { try { Service = service; Model = (await Service.Notes.GetAsync(noteId)).Entity; Model.SetIsDirty(false); FolderWithServiceRef = new FolderWithServiceRef { ServiceRef = Store.GetServiceRef(service.IdServiceRef), FolderInfo = Model?.FolderDto }; var resGetWindow = await Service.Notes.GetWindowAsync(Model.NoteId, await PostItGetUserId()); if (resGetWindow.IsValid) { WindowPostIt = resGetWindow.Entity; } else { WindowPostIt = await GetNewWindowPostIt(); } WindowPostIt.Visible = true; await Service.Notes.SaveWindowAsync(WindowPostIt); WindowPostIt.SetIsDirty(false); if (refreshView) { View.RefreshView(); } return(true); } catch (Exception ex) { View.ShowInfo(ex.Message); return(false); } }
public async override Task <bool> SaveModel() { View.RefreshModel(); if (!Model.IsDirty() && !WindowPostIt.IsDirty()) { return(true); } try { var isNew = (Model.NoteId == Guid.Empty); var msgVal = Model.GetErrorMessage(); if (!string.IsNullOrEmpty(msgVal)) { View.ShowInfo(msgVal); return(false); } var response = await Service.Notes.SaveAsync(Model); if (response.IsValid) { Model = response.Entity; Model.SetIsDirty(false); Model.SetIsNew(false); if (!isNew) { OnSavedEntity(response.Entity); } else { OnAddedEntity(response.Entity); } } else { View.ShowInfo(response.Message); } if (WindowPostIt != null) { if (WindowPostIt.NoteId == Guid.Empty) { WindowPostIt.NoteId = Model.NoteId; } var responseWinPostIt = await Service.Notes.SaveWindowAsync(WindowPostIt); WindowPostIt.SetIsDirty(false); } } catch (Exception ex) { View.ShowInfo(ex.Message); return(true); } return(true); }