public Fixture() { this.NoteRepository = Substitute.For <INoteRepository>(); this.Note = new Note(474, "name", "the notes", DateTime.UtcNow, DateTime.UtcNow); this.NoteDto = new NoteDto() { Id = this.Note.Id, Title = this.Note.Title, ModifiedOn = this.Note.ModifiedOn, CreatedOn = this.Note.CreatedOn, Text = this.Note.Text }; this.NoteRepositoryDto = new NoteRepositoryDto() { Id = this.Note.Id, Title = this.Note.Title, Text = this.Note.Text, CreatedOn = this.Note.CreatedOn, ModifiedOn = this.Note.ModifiedOn, }; var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new MapperProfile()); }); var mapper = mappingConfig.CreateMapper(); this.Mapper = mapper; }
public async Task <bool> SaveInfoInRepository(string repositoryAlias, string subjet, string message, int?folderNumber) { ServiceRef serviceRef = GetServiceRef(repositoryAlias); NoteDto note = (await serviceRef.Service.Notes.NewAsync()).Entity; note.Topic = subjet; note.Description = message; if (folderNumber == null) { note.FolderId = (await serviceRef.Service.Folders.GetHomeAsync()).Entity.FolderId; } else { var folder = (await serviceRef.Service.Folders.GetAsync((int)folderNumber)).Entity; if (folder != null) { note.FolderId = folder.FolderId; } else { throw new Exception("Invalid parameter."); } } var res = (await serviceRef.Service.Notes.SaveAsync(note)).IsValid; return(res); }
public IActionResult Note(int id, string slug) { if (id == default(int)) { return(NotFound()); } NoteDto note = _noteService.Get(id, honorVisibilityRule: !HttpContext.User.IsInRole(Administrator)); if (note == null) { return(NotFound()); } if (!note.IsVisible) { if (!HttpContext.User.IsInRole(Administrator)) { return(NotFound()); } } if (slug != note.Slug) { return(RedirectToRoutePermanent("notes", new { id = note.Id, slug = note.Slug })); } return(View(note)); }
public async Task <IActionResult> Open(int?id) { if (id == null) { return(NotFound()); } NoteDto noteDto = await noteService.FindNoteDtoById((int)id); if (noteDto == null) { return(NotFound()); } try { NoteDto newNoteDto = await noteService.OpenNote((int)id); return(RedirectToAction(nameof(Index), new { n = newNoteDto.Guid })); } catch { return(Problem()); } }
public async Task <ActionResult <NoteDto> > PutAsync(string id, NoteDto noteDto) { var command = new PostPutNote.Command(noteDto, id); var result = await _mediator.Send(command); return(CreatedAtAction(nameof(GetByIdAsync), new { result.Id }, result)); }
public async Task <IActionResult> Index(string n) { if (n == null) { return(View("Create")); } NoteDto noteDto = await noteService.FindNoteByGuid(n); NoteViewModel note = MapNoteDtoToViewModel(noteDto); //var note = await _context.Notes.FirstOrDefaultAsync(m => m.Guid == n); if (note == null) { return(NotFound()); } if (note.SealedUntil > DateTime.Today) { return(View("Sealed", note.SealedUntil)); } if (note.Status == Models.NoteStatus.Open) { return(View(note)); } return(View("Open", note)); }
public void DeleteNote(NoteDto note) { var tokenToRemove = _dbContext.Notes.ToList().Find(x => x.NoteId == note.NoteId.ToString()); _dbContext.Notes.Remove(tokenToRemove); _dbContext.SaveChanges(); }
public object DeleteNote(NoteDto noteDto) { const string url = "http://localhost:5000/Note"; var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(noteDto)); var requestWeb = WebRequest.CreateHttp(url); // 'desabilitar' ssl requestWeb.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; requestWeb.Method = "DELETE"; requestWeb.ContentType = "application/json"; requestWeb.ContentLength = data.Length; requestWeb.UserAgent = "RequisicaoWebDemo"; using (var stream = requestWeb.GetRequestStream()) { stream.Write(data, 0, data.Length); stream.Close(); } try { using var resposta = requestWeb.GetResponse(); using var streamOne = resposta.GetResponseStream(); using var reader = new StreamReader(streamOne); return(JsonConvert.DeserializeObject <List <string> >(reader.ReadToEnd())); } catch (WebException ex) { using var stream = ex.Response.GetResponseStream(); using var reader = new StreamReader(stream); return(JsonConvert.DeserializeObject <List <string> >(reader.ReadToEnd())); } }
public IHttpActionResult UpdateNote(NoteDto note) { try { UserDto user; if (!GiveMeAUserDto_IfThisMotherFuckerHasAGodDamnToken_AKA_WhatWouldHaveBeenMyAuthenticationFilterAttribute(out user)) { throw new Exception("This mother f****r need a god damn token"); } CurrentUser = user; AddHistory = AuditAddRepo.Read().Where(auditAdd => auditAdd.UserId == CurrentUser.Id); if (!AddHistory.Any(add => add.Entity == "Note" && add.EntityId == note.Id && add.UserId == CurrentUser.Id)) { throw new Exception("This mother f****r didnt make this note"); } return(Ok(NoteRepo.Update(note))); } catch (Exception x) { return(BadRequest(x.Message)); } }
public void Post([FromBody] NoteDto noteDto) { var note = new Note(noteDto.Title, noteDto.Content); _dbContext.Notes.Add(note); _dbContext.SaveChanges(); }
public IActionResult Post([FromBody] NoteDto note) { var newId = Guid.NewGuid(); note = _noteService.Create(newId, note.Title, note.Content); return(Created($"api/notes/{newId}", note)); }
public NoteDto InsertNote() { NoteDto note = Mapper.Map <NoteDto>(((NotesContext)Context).Notes.Add(new Note())); Context.SaveChanges(); return(note); }
public async Task <int> CreateNoteAsync(NoteDto noteDto) { var sql = $"INSERT INTO Note ({nameof(noteDto.Name)},{nameof(noteDto.Description)},{nameof(noteDto.CreatedDate)},{nameof(noteDto.UpdateDate)}) VALUES " + $"(@{nameof(noteDto.Name)},@{nameof(noteDto.Description)},@{nameof(noteDto.CreatedDate)},@{nameof(noteDto.UpdateDate)})"; return(await _con.ExecuteAsync(sql, noteDto)); }
private NoteActionResponse GetNotesFunc(List <NoteDto> savedNotes, NoteDto requesNote, AccountDto account, NoteActionRequest request) { return(new NoteActionResponse() { Notes = _baseService.FindUserNotes(account.AccountId).ToList() }); }
public async Task <ActionResult <NoteDto> > GetForSlide(string place, string presenter, string slug, int number, CancellationToken ct) { if (!User.Identity.IsAuthenticated) { return(new NoteDto()); } var slideIdentifier = $"{place}/{presenter}/{slug}/{number}"; var user = User.FindFirstValue(DeckHubClaimTypes.Handle); try { var existingNote = await _context.Notes .SingleOrDefaultAsync(n => n.UserHandle == user && n.SlideIdentifier == slideIdentifier, ct) .ConfigureAwait(false); if (existingNote == null) { return(new NoteDto { UserIsAuthenticated = true }); } var dto = NoteDto.FromNote(existingNote); dto.UserIsAuthenticated = true; return(dto); } catch (Exception ex) { _logger.LogError(EventIds.DatabaseError, ex, ex.Message); throw; } }
public ActionResult <NoteDto> Post([FromBody] NoteDto note) { try { var fields = _service.ValidateEmptyField(note); if (fields.Count != 0) { return(BadRequest(fields)); } var noteModel = _service.BuildStudentNote(note); var validate = _service.ValidateCreateNote(noteModel); if (validate.Count != 0) { return(BadRequest(validate)); } _service.Create(noteModel); return(Ok(_service.NoteToDto(noteModel))); } catch (Exception) { return(BadRequest(new List <string> { $"Não foi possivel cadastrar a nota do estudante [ {note.Student} ]" })); } }
public async Task <IActionResult> SetForSlide(string place, string presenter, string slug, int number, [FromBody] NoteDto note, CancellationToken ct) { var slideIdentifier = $"{place}/{presenter}/{slug}/{number}"; var user = User.FindFirstValue(DeckHubClaimTypes.Handle); var existingNote = await _context.Notes .SingleOrDefaultAsync(n => n.UserHandle == user && n.SlideIdentifier == slideIdentifier, ct) .ConfigureAwait(false); if (existingNote == null) { existingNote = new Note { Public = false, SlideIdentifier = slideIdentifier, UserHandle = user }; _context.Notes.Add(existingNote); } existingNote.NoteText = note.Text; existingNote.Timestamp = DateTimeOffset.UtcNow; await _context.SaveChangesAsync(ct).ConfigureAwait(false); return(Accepted()); }
public async Task <NoteDto> CreateNote(NoteDto noteDto) { Note note = MapDtoToNote(noteDto); Note createdNote = await noteWorkflow.CreateNote(note); return(MapNoteToDto(createdNote)); }
public NoteDto UpdateNote(NoteDto note) { NoteDto result = Mapper.Map <NoteDto>(((NotesContext)Context).Notes.Attach(Mapper.Map <Note>(note))); Context.SaveChanges(); return(result); }
public async Task <ServiceResponse <GetNoteDto> > AddNewNote(NoteDto newNote) { ServiceResponse <GetNoteDto> serviceResponse = new ServiceResponse <GetNoteDto>(); try { newNote.CreatedDate = DateTime.Now; newNote.UpdatedDate = newNote.CreatedDate; newNote.UserId = GetUserId(); _context.Notes.Add(Mapper.Map <NoteDto, Note>(newNote)); await _context.SaveChangesAsync(); Note noteInDb = _context.Notes.Where(n => n.UserId == newNote.UserId && n.Title.ToLower() == newNote.Title.ToLower()) .OrderByDescending(n => n.Id) .FirstOrDefault(); serviceResponse.Data = Mapper.Map <Note, GetNoteDto>(noteInDb); return(serviceResponse); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; return(serviceResponse); } }
public async Task <int> Putty([FromBody] NoteDto noteDto) { Note note = _mapper.Map <Note>(noteDto); _context.Note.Update(note); return(await _context.SaveChangesAsync()); }
public async Task GetAllAsync_ShouldReturnListNote() { // Arrange var noteDto = new NoteDto { Id = "99" }; _mediator.Send(Arg.Any <GetAllNote.Query>()) .Returns(new GetAllNote.Response(new List <NoteDto> { noteDto })); // Act var actionResult = await _sut.GetAllAsync(); // Assert if (actionResult.Result is OkObjectResult result) { result.StatusCode.Should().Be(200); if (result.Value is List <NoteDto> value) { value.Should().HaveCount(1); } } }
public HttpResponseMessage EditNote(int id, NoteDto notedto) { var repo = new NoteRepository(); var result = repo.Update(notedto); return(Request.CreateUpdateRecordResponse(result)); }
private void UpdateNote() { Note.Title = TextBox_Title.Text; Note.Content = TextBox_Content.Text; NoteDto note = Note; note = NotesApi.GetData(NotesApi.Execute <NoteDto>("Dashboard/UpdateNote", RestSharp.Method.POST, note)); }
public NoteFragment(NoteDto note) { Note = note; CommandBindings.Add(new CommandBinding(NavigationCommands.GoToPage, (sender, e) => Process.Start((string)e.Parameter))); InitializeComponent(); }
public static TagDto FromTag(Tag tag) => new TagDto { TagId = tag.TagId, Name = tag.Name, Slug = tag.Slug, Notes = tag.NoteTags.Select(x => NoteDto.FromNote(x.Note, false)).ToList() };
public void Put(int id, [FromBody] NoteDto noteDto) { var note = _dbContext.Notes.SingleOrDefault(n => n.Id == id); note.Title = noteDto.Title; note.Content = noteDto.Content; _dbContext.Notes.Update(note); }
private NoteActionResponse RemoveNoteFunc(List <NoteDto> savedNotes, NoteDto requesNote, AccountDto account, NoteActionRequest request) { _baseService.DeleteNote(account.AccountId, requesNote.NoteId); return(new NoteActionResponse() { Notes = _baseService.FindUserNotes(account.AccountId) }); }
public async Task <NoteDto> CreateNote(NoteDto note, string email, CancellationToken cancellationToken) { var mappedNote = mapper.Map <Note>(note); var result = await repository.CreateNote(mappedNote, email, cancellationToken); return(mapper.Map <NoteDto>(result)); }
private NoteActionResponse CreateNoteFunc(List <NoteDto> savedNotes, NoteDto requesNote, AccountDto account, NoteActionRequest request) { _baseService.SaveNote(account.AccountId, Guid.NewGuid(), "New Note"); return(new NoteActionResponse() { Notes = _baseService.FindUserNotes(account.AccountId) }); }
public NoteDto GetNote(string sessionKey, string noteId) { NoteDto retVal = new NoteDto(); long id = 0; long.TryParse(noteId, out id); retVal.Id = id; retVal.Text = "Note: " + DateTime.Now.ToString(); return retVal; }
public NoteDto GetNote(int id) { var note = _notesRepository.GetNote(id); var noteDto = new NoteDto { Text = note.Text, Id = note.Id }; return noteDto; }
public ActionResult Edit(NoteViewModel model) { NoteDto noteDto = new NoteDto { Id = model.Id, Text = model.Text }; _notesService.EditNote(noteDto); return RedirectToAction("Index"); }
public void EditNote(NoteDto noteDto) { _notesRepository.EditNote(noteDto.Id, noteDto.Text); }