public void adding_note_in_russian_should_return_list_of_note_in_russian() { File.WriteAllText(GetAllTest.notesFilePath, string.Empty); notesRepository.AddNote("собаки и кошки"); string[] requiredList = { "собаки и кошки" }; string[] originalList = notesRepository.GetAll().Select(note => note.Data).ToArray(); CollectionAssert.AreEqual(originalList, requiredList); }
public void AddNote(string note) { NotesRepository notesRepository = new NotesRepository(); NotesRepository.SetPath(pathAdd); notesRepository.AddNote(note); }
public async Task <Note> CreateAsync(Note entity) { var context = _httpContextAccessor.HttpContext; var userName = context.GetUserName(); if (userName is null) { throw new JsonApiException(new Error(HttpStatusCode.Unauthorized)); } var creator = await _authors.GetByUserName(userName); if (!creator.HasValue) { throw new JsonApiException(new Error(HttpStatusCode.Unauthorized)); } var input = new NotesRepository.NoteInput( title: entity.Title ?? throw new JsonApiException(new Error(HttpStatusCode.BadRequest)), content: entity.Content ?? throw new JsonApiException(new Error(HttpStatusCode.BadRequest))); var addedNote = await _notes.AddNote(input, creator.Value); return(Note.FromNote(addedNote)); }
public async Task <IActionResult> AddNote([FromBody] string?title, [FromBody] string?content) { var userName = this.HttpContext.GetUserName(); if (userName is null) { return(Unauthorized()); } var creator = await _authors.GetByUserName(userName, _cancellation); if (!creator.HasValue) { return(Unauthorized()); } if (title is null || content is null) { return(BadRequest()); } var input = new NotesRepository.NoteInput(title, content); var note = await _notes.AddNote(input, creator.Value, _cancellation); return(new RestResult(NoteDTO.FromNote(note))); }
public async ValueTask <AddNoteResponse> Handle(AddNoteRequest request, ServerCallContext ctx) { var userName = ctx.GetUserName(); var creator = await _authors.GetByUserName(userName, ctx.CancellationToken); if (!creator.HasValue) { throw new UserNotFoundRpcException(userName); } if (string.IsNullOrEmpty(request.Title)) { throw new ArgumentNullRpcException("title"); } if (string.IsNullOrEmpty(request.Content)) { throw new ArgumentNullRpcException("content"); } var input = new NotesRepository.NoteInput(request.Title, request.Content); var newNote = await _notes.AddNote(input, creator.Value, ctx.CancellationToken); return(new AddNoteResponse { CreatedNote = ModelMapper.MapNote(newNote) }); }
public void one_note_adding_should_add_one_note_to_file() { File.WriteAllText(AddNoteTest.notesFilePath, string.Empty); string note = "stay there"; NotesRepository.SetPath(AddNoteTest.notesFilePath); notesRepository.AddNote(note); StreamReader inputFile = new StreamReader(notesFilePath, false); Assert.AreEqual(inputFile.ReadLine(), note); inputFile.Close(); }
public void AddNotesToMemory() { File.Delete("..\\..\\..\\testData\\FileWithoutAddedItem.json"); repositoryWithoutAddedNote.OpenFile("..\\..\\..\\testData\\FileWithoutAddedItem.json"); Note note = new Note(); note.Text = "строка без смысла"; List <Note> manualAddList = new List <Note> { note }; repositoryWithoutAddedNote.AddNote(note); List <Note> listWithAddViaFunction = repositoryWithoutAddedNote.GetAllNotes().ToList <Note>(); Assert.AreEqual(manualAddList.Count(), listWithAddViaFunction.Count()); Assert.AreEqual(manualAddList[0].Text, listWithAddViaFunction[0].Text); }
public IActionResult Post([FromBody] NotesModel NewNote) { var identity = HttpContext.User.Identity as ClaimsIdentity; var userid = identity.FindFirst(ClaimTypes.Name).Value; int Userid = Int32.Parse(userid); if (!ModelState.IsValid) { return(BadRequest()); } try { return(Ok(NotesRepository.AddNote(NewNote, Userid))); } catch (Exception ex) { return(BadRequest($"Failed: {ex}")); } }
public ActionResult AddNotes(NoteModel Nm, string SaveOrPublish) { ViewBag.Title = "AddNotes"; ViewBag.Authorized = true; ViewBag.LoadValidationScript = true; if (Session["UserID"] == null) { return(RedirectToAction("Login", "Authentication", new { ReturnUrl = "/RegisteredUser/AddNotes" })); } SearchNotesModel FilterData = new SearchNotesModel(); FilterData.Type = NotesFilters.Types(); FilterData.Category = NotesFilters.Categories(); FilterData.Country = NotesFilters.Countries(); ViewBag.FilterData = FilterData; //check uploaded files and their size if (Nm.PreviewFile != null && (Path.GetExtension(Nm.PreviewFile.FileName).ToLower() != ".pdf" || Nm.PreviewFile.ContentLength > 31457280)) { ModelState.AddModelError("PreviewFile", "Only PDF files that are under 30MBs are allowed."); } long NoteSize = 0; foreach (HttpPostedFileBase file in Nm.NotesFiles) { if (file == null) { ModelState.AddModelError("NotesFiles", "Make sure you have uploaded PDF file(s) that are under 30MBs"); } else if (Path.GetExtension(file.FileName).ToLower() != ".pdf") { ModelState.AddModelError("NotesFiles", "Only PDF file(s) are allowed."); } if (file != null) { NoteSize += file.ContentLength; } } if (NoteSize > 31457280) { ModelState.AddModelError("NotesFiles", "Combine PDF(s) size should not exceeds 30MBs"); } if (Nm.NotesCoverPage != null && !MimeMapping.GetMimeMapping(Nm.NotesCoverPage.FileName).ToLower().Contains("image")) { ModelState.AddModelError("NotesCoverPage", "Only Images are allowed."); } if (!ModelState.IsValid) { return(View(Nm)); } //0 for draft 1 for submit for review if (SaveOrPublish == "Save") { Nm.Status = 0; } else if (SaveOrPublish == "Publish") { Nm.Status = 1; } else { ViewBag.Message = "Adding / Editing note didnt go as expected please try again."; return(View(Nm)); } ViewBag.Title = "AddNotes"; ViewBag.Authorized = true; ViewBag.LoadValidationScript = true; string UID = User.Identity.Name; int result = NotesRepository.AddNote(Nm, Convert.ToInt32(UID), Server.MapPath("~")); if (result < 1) { ViewBag.Message = "Adding/Editing note didnt go as expected please try again."; return(View(Nm)); } if (SaveOrPublish == "Publish") { ViewBag.SellerName = Session["FullName"]; ViewBag.NoteName = Nm.Title; SendMail.SendEmail(new EmailModel() { EmailTo = SystemConfigData.GetSystemConfigData("AdminEmails").DataValue.Split(';'), EmailSubject = Session["FullName"].ToString() + " sent his note for review.", EmailBody = this.getHTMLViewAsString("~/Views/Email/RequestToReview.cshtml") }); TempData["Message"] = "Note has been submitted for review, we will send you mail when it gets approved."; } else { TempData["Message"] = "Note has been successfully saved in Drafts"; } return(RedirectToAction("Dashboard", "RegisteredUser")); }
public NotesMutation(NotesRepository notes, AuthorsRepository authors) { FieldAsync <NonNullGraphType <NoteGraphType> >( name: "addNote", description: "Add a new note.", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <NoteInputType> >() { Name = "note", Description = "The new note to be added." }), resolve: async ctx => { var userName = ctx.RequireUserName(); var creator = await authors.GetByUserName(userName, ctx.CancellationToken); if (!creator.HasValue) { return(Errors.InvalidUsernameError <object>()); } var newNote = ctx.GetRequiredArgument <NotesRepository.NoteInput>("note"); return(await notes.AddNote(newNote, creator.Value, ctx.CancellationToken)); }); FieldAsync <NoteGraphType>( name: "addKeyword", description: "Add a new keyword to an existing note with the given id.", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> >() { Name = "noteId", Description = "The id of the note the keyword should be added to." }, new QueryArgument <NonNullGraphType <KeywordGraphType> >() { Name = "keyword", Description = "The keyword to add to the note." }), resolve: async ctx => { var prefixedId = ctx.GetRequiredArgument <string>("noteId"); var id = IdParser.ParsePrefixedId(prefixedId, NoteGraphType.IdPrefix); var keyword = ctx.GetRequiredArgument <Keyword>("keyword"); var userName = ctx.RequireUserName(); var editor = await authors.GetByUserName(userName, ctx.CancellationToken); if (!editor.HasValue) { return(Errors.InvalidUsernameError <object>()); } var found = await notes.AddKeywordToNote(id, keyword, editor.Value, ctx.CancellationToken); if (!found) { return(Errors.NotFound <object>("Note", prefixedId)); } return(await notes.GetById(id, ctx.CancellationToken)); }); FieldAsync <BooleanGraphType>( name: "deleteNote", description: "Deletes the note with the given id, if present.", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> >() { Name = "noteId", Description = "The id of the note that should be deleted." }), resolve: async ctx => { var prefixedId = ctx.GetRequiredArgument <string>("noteId"); var id = IdParser.ParsePrefixedId(prefixedId, NoteGraphType.IdPrefix); var found = await notes.Remove(id, ctx.CancellationToken); if (!found) { return(Errors.NotFound <bool>("Note", prefixedId)); } return(true); }); FieldAsync <NonNullGraphType <AuthorGraphType> >( name: "signup", description: "Create a new author.", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <AuthorInputType> >() { Name = "author", Description = "The new author to be added." }), resolve: async ctx => { var newAuthor = ctx.GetRequiredArgument <AuthorsRepository.AuthorInput>("author"); return(await authors.AddAuthor(newAuthor, ctx.CancellationToken)); }); }
public bool SetNote(int idNote, int idUser, string note, string title) { NotesRepo.AddNote(idNote, idUser, title, note); return(true); }