public async Task <IActionResult> CreateAsync(CreateNoteViewModel model) { if (!ModelState.IsValid) { ViewData["ErrorMessage"] = "Invalid form submission"; return(PartialView("_CreateNote", model)); } BaseResponse _Response = new BaseResponse(); model.OwnerUID = User.FindFirstValue(ClaimTypes.NameIdentifier); _Response = await __NoteManager.CreateAsync(__Mapper.Map <CreateNoteRequest>(model)); if (!_Response.Success) { ModelState.AddModelError("Error", _Response.Message); return(await CreateModalAsync(model.EquipmentUID)); } return(Json(new { success = $"{GlobalConstants.SUCCESS_ACTION_PREFIX} created {ENTITY_NAME}." })); }
public static void AddNoteMutationsAsync <TSourceType>( this ObjectGraphType <TSourceType> mutator, DataAccessUserContext context, IUnitOfWork unitOfWork, INoteManager notes, string writeNotesPerm, GetNoteOwnerFunc <TSourceType> getNoteOwner ) where TSourceType : class { mutator.FieldAsync <BooleanGraphType>( "addNote", "Adds a note.", new QueryArguments( // category: String! new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "category" }, // content: String! new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "content" } ), async ctx => { await context.EnforceHasPolicyAsync(writeNotesPerm); using (var scope = unitOfWork.Begin("Add note")) { var owner = getNoteOwner(ctx); var note = new NoteEntry { NoteOwner = owner, Category = ctx.GetArgument <string>("category"), Content = ctx.GetArgument <string>("content") }; await notes.CreateAsync(note); scope.Commit(); } return(true); } ); mutator.FieldAsync <BooleanGraphType>( "deleteNotes", "Deletes a set of notes.", new QueryArguments( // ids: [ID!]! new QueryArgument <NonNullGraphType <ListGraphType <NonNullGraphType <IdGraphType> > > > { Name = "ids" } ), async ctx => { await context.EnforceHasPolicyAsync(writeNotesPerm); using (var scope = unitOfWork.Begin("Delete notes")) { var owner = getNoteOwner(ctx); foreach (var id in ctx.GetArgument <List <int> >("ids")) { var note = await notes.GetByIdAsync(id); if (!note.Succeeded) { scope.Rollback("Note was not found"); return(false); } if (!owner.NoteEntries.Any(e => e.NoteEntryId == note.Value.NoteEntryId)) { scope.Rollback("Note does not belong to contact"); return(false); } notes.Delete(note.Value); } scope.Commit(); } return(true); } ); }