public static TagApiModel FromTag(Tag tag) => new TagApiModel { TagId = tag.TagId, Name = tag.Name, Slug = tag.Slug, Notes = tag.NoteTags.Select(x => NoteApiModel.FromNote(x.Note, false)).ToList() };
public Note UpdateNote(int id, NoteApiModel model) { var wantedNote = AllNotes.FirstOrDefault(note => note.Id == id); if (wantedNote != null) { wantedNote.Text = model.Text; wantedNote.CreateAt = DateTime.UtcNow; } return(wantedNote); }
public IActionResult Post([FromBody] NoteApiModel noteModel) { var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)); var dbNote = _noteRepository.Insert(new Note { Text = noteModel.Text, Title = noteModel.Title, UserId = userId }); return(Ok(dbNote)); }
public async Task <SaveNoteCommand.Response> HandleSaveNoteCommand(SaveNoteCommand.Request request, CancellationToken cancellationToken, SaveNoteCommand.Response response) { var note = await _context.Notes.FindAsync(response.NoteId); await _hubContext.Clients.All.SendAsync("message", new { Type = "[Note] Saved", Payload = new { note = NoteApiModel.FromNote(note) } }); return(response); }
public int Create(NoteApiModel apiModel) { var createdNote = _noteRepository.Create(apiModel); if (createdNote != null) { return(createdNote.ID); } else { return(0); } }
public Note AddNote(NoteApiModel model) { var randomizer = new Randomizer(); var newNote = new Note { CreateAt = DateTime.UtcNow, Id = randomizer.Int(), Text = model.Text }; AllNotes.Add(newNote); return(newNote); }
public IHttpActionResult Get(int id) { NoteDTO noteDto = NoteService.GetNote(id, userId); noteDto.Picture = NoteService.GetPicture(id); NoteApiModel noteModel = mapper.Map <NoteDTO, NoteApiModel>(noteDto); //if (noteModel.Picture != null) //{ // noteModel.Picture.PathToPicture = Url.Route("Default", new { controller = "Pictures", action = "Index", id = noteModel.Id }); //} return(Json(noteModel)); }
public NOTE Create(NoteApiModel apiModel) { var newNote = new NOTE(); newNote.NoteBody = apiModel.body; if (apiModel.account != 0) { newNote.ACCOUNT_ID = apiModel.account; } if (apiModel.campaign != 0) { newNote.CAMPAIGN_ID = apiModel.campaign; } if (apiModel.contact != 0) { newNote.CONTACT_ID = apiModel.contact; } if (apiModel.deal != 0) { newNote.DEAL_ID = apiModel.deal; } if (apiModel.lead != 0) { newNote.LEAD_ID = apiModel.lead; } if (apiModel.taskTemplate != 0) { newNote.TASK_TEMPLATE_ID = apiModel.taskTemplate; } newNote.CreatedAt = DateTime.Now; newNote.CreatedBy = apiModel.createdBy.id.GetValueOrDefault(); db.NOTEs.Add(newNote); db.SaveChanges(); return(newNote); }
public async Task <NoteResponse.UpdateResponse> Update(NoteApiModel model) { var response = await PostEncodedContentWithSimpleResponse <NoteResponse.UpdateResponse, NoteApiModel>(updateUri, model); return(response); }
public async Task <NoteResponse.AddResponse> AddNew(NoteApiModel model) { var response = await PostEncodedContentWithSimpleResponse <NoteResponse.AddResponse, NoteApiModel>(createUri, model); return(response); }
public HttpResponseMessage CreateNote([FromUri] int id) { var response = new HttpResponseMessage(); ResponseFormat responseData = new ResponseFormat(); IEnumerable <string> headerValues; if (Request.Headers.TryGetValues("Authorization", out headerValues)) { string jwt = headerValues.FirstOrDefault(); AuthorizationService _authorizationService = new AuthorizationService().SetPerm((int)EnumPermissions.NOTE_CREATE); //validate jwt var payload = JwtTokenManager.ValidateJwtToken(jwt); if (payload.ContainsKey("error")) { if ((string)payload["error"] == ErrorMessages.TOKEN_EXPIRED) { response.StatusCode = HttpStatusCode.Unauthorized; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.TOKEN_EXPIRED; } if ((string)payload["error"] == ErrorMessages.TOKEN_INVALID) { response.StatusCode = HttpStatusCode.Unauthorized; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.TOKEN_INVALID; } } else { var userId = Convert.ToInt32(payload["id"]); var isAuthorized = _authorizationService.Authorize(userId); if (isAuthorized) { string noteBody = HttpContext.Current.Request.Form["body"]; if (!string.IsNullOrEmpty(noteBody)) { //create a note NoteApiModel apiModel = new NoteApiModel(); apiModel.body = noteBody; apiModel.createdBy = new UserLinkApiModel() { id = userId }; apiModel.account = id; var createdNote = _noteService.Create(apiModel); //create files and link them to note if (HttpContext.Current.Request.Files.Count > 0) { var allFiles = HttpContext.Current.Request.Files; foreach (string fileName in allFiles) { HttpPostedFile uploadedFile = allFiles[fileName]; FileManager.File file = new FileManager.File(uploadedFile); _noteService.AddFile(createdNote, file); } } response.StatusCode = HttpStatusCode.OK; responseData = ResponseFormat.Success; responseData.message = SuccessMessages.NOTE_ADDED; } else { response.StatusCode = HttpStatusCode.BadRequest; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.NOTE_EMPTY; } } else { response.StatusCode = HttpStatusCode.Forbidden; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.UNAUTHORIZED; } } } else { response.StatusCode = HttpStatusCode.Unauthorized; responseData = ResponseFormat.Fail; responseData.message = ErrorMessages.UNAUTHORIZED; } var json = JsonConvert.SerializeObject(responseData); response.Content = new StringContent(json, Encoding.UTF8, "application/json"); return(response); }
internal ApiResultNoteApiModel(NoteApiModel data) { Data = data; }