示例#1
0
        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());
            }
        }
示例#2
0
        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));
            }
        }
示例#3
0
        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());
            }
        }
示例#4
0
 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()
     });
 }
示例#5
0
        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));
        }
示例#6
0
        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));
            }
        }
示例#7
0
        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);
        }
示例#8
0
        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();
 }
示例#10
0
 public Task CreateNoteAsync(NoteCreateDto note)
 {
     return(_restService.AddNewNoteAsync(note));
 }