public async Task <ActionResult <Note> > Create(NoteCreateDto note) { try { if (note == null || string.IsNullOrEmpty(note.Content)) { return(StatusCode(StatusCodes.Status400BadRequest, "Контент должен быть указан")); } var entity = new Note { Content = note.Content, Title = string.IsNullOrEmpty(note.Title) ? null : note.Title, }; await _context.AddAsync(entity); await _context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created, entity)); } catch (Exception e) { Console.WriteLine(e); return(BadRequest()); } }
public async Task <IBusinessResult> CreateNoteAsync(NoteCreateDto noteCreateDto) { if ((await _noteDal.GetAsync(p => p.NoteTitle.Equals(noteCreateDto.NoteTitle))).Data != null) { return(new BusinessResult("Bu başlığı kullanan bir not sistemde zaten kayıtlı! Lütfen not başlığını değiştirin.", ProcessResultType.Warning, ResultType.CreateUnSuccess)); } var noteEntity = _mapper.Map <Note>(noteCreateDto); noteEntity.CreatedDateTime = DateTime.Now; noteEntity.IsDeleted = false; var createResult = await _noteDal.CreateAsync(noteEntity); if (createResult.Exception != null) { return(new BusinessResult("Sistemde Bir Hata Oluştu!", ProcessResultType.Error, ResultType.CreateUnSuccess)); } if (createResult.Data != null && createResult.IsCommited) { return(new BusinessResult("Not Başarıyla Kayıt Edildi!", ProcessResultType.Completed, ResultType.CreateSuccess)); } else { return(new BusinessResult("Not Bilinmeyen Bir Nedenden Dolayı Kayıt Edilemedi!", ProcessResultType.Completed, ResultType.CreateUnSuccess)); } }
public async Task <ActionResult <Note> > Put(int id, NoteCreateDto note) { try { var entity = await _context.Notes.FindAsync(id); if (entity == null) { return(NotFound("такой записи нет")); } if (note == null || string.IsNullOrEmpty(note.Content)) { return(StatusCode(StatusCodes.Status400BadRequest, "Контент должен быть указан")); } entity.Content = note.Content; entity.Title = string.IsNullOrEmpty(note.Title) ? null : note.Title; await _context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status200OK, entity)); } catch (Exception e) { Console.WriteLine(e); return(BadRequest()); } }
public void Post([FromBody] NoteCreateDto newNote) { _noteRepository.AddNote(new Note { Id = ObjectId.GenerateNewId().ToString(), Body = newNote.Body, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now, UserId = GetUserId() }); }
public ActionResult <NoteReadDto> CreateNote(NoteCreateDto noteCreateDto) { var noteModel = _mapper.Map <Note>(noteCreateDto); _repository.CreateNote(noteModel); _repository.SaveChanges(); var noteReadDto = _mapper.Map <NoteReadDto>(noteModel); return(CreatedAtRoute(nameof(GetNoteById), new { Id = noteReadDto.ID }, noteReadDto)); }
public async Task <IActionResult> CreateAsync(NoteCreateDto noteCreateDto) { var createResult = await _noteService.CreateNoteAsync(noteCreateDto); if (createResult.ProcessResultType == ProcessResultType.Completed) { return(Ok(createResult)); } else { return(BadRequest(createResult)); } }
public async Task <IBusinessResult> CreateAsync(NoteCreateDto noteCreateDto) { StringContent httpContent = new StringContent(JsonConvert.SerializeObject(noteCreateDto), Encoding.UTF8, "application/json"); string lastUrl = url + route + "create"; IBusinessResult result; using (HttpResponseMessage response = await httpClient.PostAsync(lastUrl, httpContent)) { //response.EnsureSuccessStatusCode(); var apiResult = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <BusinessResult>(apiResult); } return(result); }
public async Task AddNewNoteAsync(NoteCreateDto note) { Uri uri = new Uri(string.Format(Constants.RestUrl, string.Empty)); try { string json = JsonConvert.SerializeObject(note); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _client.PostAsync(uri, content); if (response.IsSuccessStatusCode) { Debug.WriteLine(@"\tNote succesfully added."); } } catch (Exception ex) { Debug.WriteLine(@"\tERROR: {0}", ex.Message); } }
public async Task <IActionResult> Post([FromRoute] Guid userId, [FromBody] NoteCreateDto noteCreateDto) { throw new NotImplementedException(); }
public Task CreateNoteAsync(NoteCreateDto note) { return(_restService.AddNewNoteAsync(note)); }