public async Task <IActionResult> CreateNote([FromBody] CreateNoteResource model) { try { var note = _mapper.Map <CreateNoteResource, Note>(model); note.UserId = ObjectId.Parse(model.UserId); note.Category.Id = ObjectId.Parse(model.CategoryId); if (string.IsNullOrWhiteSpace(note.Title)) { return(BadRequest("Title not allowed!")); } note.Create = DateTime.UtcNow; var resutl = await _noteService.AddNote(note); if (resutl) { return(Ok("Note added.")); } return(BadRequest("Note coudn't add!")); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IActionResult Post([FromBody] NoteModel model) { try { model.UserId = GetAuthorizedUserId(); _noteService.AddNote(model); return(Ok("Successfully added note.")); } catch (UserException ex) { Log.Error("USER {userId}.{name}: {message}", ex.UserId, ex.Name, ex.Message); return(BadRequest(ex.Message)); } catch (NoteException ex) { Log.Error("NOTE {noteId} for user {userId}: {message}", ex.NoteId, ex.UserId, ex.Message); return(BadRequest(ex.Message)); } catch (Exception ex) { Log.Error("UNKNOWN Error: {message}", ex.Message); return(BadRequest("Something went wrong. Please contact support!")); } }
public async Task <ActionResult <Note> > PostNote(Note note) { note.CreationDateTime = DateTime.Now; note.LastUdpateDateTime = DateTime.Now; note = await noteService.AddNote(note); return(Ok(note)); }
public IActionResult AddNote([FromBody] Note note) { int.TryParse(User.Identity.Name, out int userId); if (_noteService.AddNote(note, userId)) { return(Ok(note)); } return(BadRequest("There is something wrong with Note info")); }
public IActionResult AddNote(Note note) { if (note == null || !ModelState.IsValid) { return(RedirectToAction("Index")); } _service.AddNote(note); return(RedirectToAction("Index")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } _noteService.AddNote(note: note); return(RedirectToPage("/Index")); }
public IDataResult <ExamResult> FinishExam(List <string> questionIds, List <string> userAnswers, UserWithIdDto user) { int correct = 0; int wrong = 0; int empty = 0; var questions = new List <Question>(); foreach (var questionId in questionIds) { var data = GetById(questionId).Data; if (data != null) { questions.Add(data); } } if (questions.Count != userAnswers.Count) { return(new ErrorDataResult <ExamResult>(QuestionMessages.UserAnswerCountNotEqualQuestionCount)); } for (int i = 0; i < questions.Count; i++) { if (userAnswers[i] == null) { empty += 1; } else if (questions[i].CorrectAnswer.ToString().ToLower() == userAnswers[i].ToLower()) { correct += 1; } else { wrong += 1; } } _noteService.AddNote(new Note { Id = CreateUniqueId.CreateId(), CategoryId = questions[0].CategoryId, Correct = correct, Wrong = wrong, Empty = empty, UserId = user.Id }); return(new SuccessDataResult <ExamResult>(new ExamResult { Correct = correct, Wrong = wrong, Empty = empty })); }
public async Task <IActionResult> AddNote(AddNoteBindingModel addNoteBindingModel) { var response = await _noteService.AddNote(addNoteBindingModel); if (response.ErrorOccurred) { return(BadRequest(response)); } return(Ok(response)); }
public ActionResult Create(Note note) { if (ModelState.IsValid) { _noteService.AddNote(note); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(CatagoryCacheHelper.GetCategoriesFromCache(), "CategoryId", "Title"); ViewBag.UserId = new SelectList(_userService.GetAllUser(), "UserId", "Name"); return(View(note)); }
public IActionResult CreateNote([FromBody] CreateModel note) { if (ModelState.IsValid) { _noteService.AddNote(note); } else { return(new BadRequestResult()); } return(Ok()); }
public IActionResult Post([FromBody] NoteModel model) { try { model.Id = GetAuthorizedUserId(); _noteService.AddNote(model); return(Ok("Successfully added note!")); } catch (Exception ex) { return(BadRequest($"Something went wrong. Please contact support! Message: {ex.Message}")); } }
public async Task <IActionResult> PostNote(long bookId, Note note) { long userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); if (!BookExists(bookId)) { return(BadRequest()); } var result = await _noteService.AddNote(userId, bookId, note); return(Ok(result)); }
public IActionResult AddNote(NoteViewModel model) { var note = mapper.Map <NoteViewModel, Note>(model); if (ModelState.IsValid) { noteService.AddNote(note); } if (note.Id > 0) { return(Redirect($"/Home/OpenBook/{note.ParentBookId}")); } return(View(model)); }
public async Task <IHttpActionResult> Add([FromBody] NoteBindingModel noteBindingModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Note note = Mapper.Map <NoteBindingModel, Note>(noteBindingModel); _noteService.AddNote(note); await _noteService.CommitAsync(); return(Ok()); }
private void ExecuteAddNoteCommand() { if (_noteService.AddNote() == true) { _eventAggregator.GetEvent <NoteChangedEvent>().Publish(String.Empty); } if (SelectedNotebookCategoryId != NotebookCategories.Default) { _eventAggregator.GetEvent <ResetNotebookCategoryEvent>().Publish(String.Empty); } // save newly created note _noteService.SaveNotes(); }
public IActionResult Post([FromBody] Note note) { try { noteservice.AddNote(note); return(Created("Added new note", note)); } catch (DuplicatesFoundException e) { return(Conflict(e.Message)); } catch (Exception ex) { return(StatusCode(500, "Internal Server Error")); } }
public IActionResult Post(Note note) { try { var result = noteService.AddNote(note); return(Created(new Uri("api/notes/" + result.NoteId, UriKind.Relative), result)); } catch (NoteNotFoundException ex) { return(NotFound(ex)); } catch (Exception ex) { return(BadRequest(ex)); } }
public ActionResult AddNote([FromForm] NoteForCloud note) { var AccountId = Convert.ToInt32(HttpContext.Items["userId"]); var email = Convert.ToString(HttpContext.Items["email"]); try { var Chache = this._distrubutedCache.GetString(key); Note AddNote = _service.AddNote(AccountId, note, email); if (Chache == null) { if (AddNote == null) { return(NotFound(new ServiceResponse <List <Note> > { StatusCode = (int)HttpStatusCode.NotFound, Message = "Internal Server Error", Data = null })); } } else { var Notes = JsonConvert.DeserializeObject <List <NotesViewModel> >(Chache); NotesViewModel note1 = new NotesViewModel { NoteId = AddNote.NoteId, Title = AddNote.Title, Description = AddNote.Description, Color = AddNote.Color, Image = AddNote.Image, IsPin = AddNote.IsPin, Remainder = AddNote.Remainder }; Notes.Add(note1); var jsonModel = JsonConvert.SerializeObject(Notes); this._distrubutedCache.SetString(key, jsonModel); return(Ok(new ServiceResponse <List <NotesViewModel> > { StatusCode = (int)HttpStatusCode.Created, Message = "successful", Data = Notes })); } _msmq.AddToQueue(AccountId + " " + "Note Added " + " " + System.DateTime.Now.ToString()); this._distrubutedCache.Remove(key); return(Ok(new ServiceResponse <Note> { StatusCode = (int)HttpStatusCode.OK, Message = "successful", Data = AddNote })); } catch (Exception) { return(BadRequest(new ServiceResponse <List <Note> > { StatusCode = (int)HttpStatusCode.BadRequest, Message = "Page Not Found", Data = null })); } }
public async void AddAndGetsTopics() { var topic = await topicService.AddTopic(new Label() { Name = "topic 1" }); Note note = new Note() { Content = "Note 1 content ", CreationDateTime = DateTime.Now, Topic = topic, LastUdpateDateTime = DateTime.Now }; note = await noteService.AddNote(note); Assert.NotNull(note); Assert.True(note.Id > 0); }
public IActionResult Post([FromBody] NoteModel noteModel) { try { _noteService.AddNote(noteModel); return(StatusCode(StatusCodes.Status201Created, "Note Created!")); } catch (NoteException e) { //log return(StatusCode(StatusCodes.Status400BadRequest, e.Message)); } catch { //log return(StatusCode(StatusCodes.Status500InternalServerError, "Something went wrong!")); } }
public ActionResult Post([FromQuery] int userId, [FromBody] NoteModel note) { try { var user = _userService.GetUserById(userId); note.UserId = userId; _noteService.AddNote(note); return(Ok("Note successfully created")); } catch (NoteException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public async Task <IActionResult> AddNote(Note note) { note.Timestamp = DateTime.Now; var result = await _noteService.AddNote(note); if (result.Success) { return(CreatedAtAction(nameof(AddNote), result.Data)); } else { return(UnprocessableEntity(new ErrorResponse() { Errors = result.Errors?.ToList(), Message = "Error creating note" })); } }
public ActionResult Post([FromQuery] int userId, [FromBody] Note note) { try { var user = _userService.GetUserById(userId); if (user == null) { throw new Exception("Not valid user ID"); } note.UserId = userId; _noteService.AddNote(note); return(Ok("Note successfully created")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private static void AddNote(INoteService noteLogic, IBookService bookLogic, IUserService userLogic, string bookId, string noteText) { if (userLogic.ActiveUser == null) { Console.WriteLine("Перед добавлением записки вы должны быть авторизованы!"); return; } if (String.IsNullOrWhiteSpace(noteText)) { Console.WriteLine("Текст некорректен!"); return; } if (!long.TryParse(bookId, out long id)) { Console.WriteLine("Id книги некорректно!"); return; } var book = bookLogic.GetById(id); if (book == null) { Console.WriteLine("Книга не найдена!"); return; } if (book.OwnerId != userLogic.ActiveUser.Id) { Console.WriteLine("Книга не принадлежит вам."); return; } Note note = new Note { Text = noteText, ParentBookId = book.Id }; Console.WriteLine(noteLogic.AddNote(note) ? "Записка успешно добавлена." : "Во время добавления записки произошла ошибка!"); }
public ActionResult Post([FromBody] NoteDto request) { try { _noteService.AddNote(request); // TODO: return create response return(Ok("Success")); } catch (NoteException ex) { Debug.WriteLine($"NOTE: {ex.Message}"); return(BadRequest(ex.Message)); } catch (Exception ex) { Debug.WriteLine($"NOTE: {ex.Message}"); return(BadRequest(ex.Message)); } }
public ActionResult Post([FromBody] NoteDto request) { try { request.UserId = GetAuthorizedUserId(); _noteService.AddNote(request); return(Ok("Success")); } catch (NoteException ex) { Debug.WriteLine($"NOTE: {ex.Message}"); return(BadRequest(ex.Message)); } catch (Exception ex) { Debug.WriteLine($"NOTE: {ex.Message}"); return(BadRequest(ex.Message)); } }
public async Task <IActionResult> AddNoteByToken([FromForm] AddNoteForm addNoteForm, List <IFormFile> images) { var id = GetIdByToken(this); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_userService.UserExistsById(id)) { return(NotFound(new Response("404", "User not found!"))); } _noteService.AddNote(id, addNoteForm); await _context.SaveChangesAsync(); _noteImageService.AddListImage(_noteService.GetNewestNote(id), images); await _context.SaveChangesAsync(); return(Ok(new Response("200", "Successfully added!"))); }
public IActionResult SubmitNote(NoteFormModel model) { var id = model.Id; if (!ModelState.IsValid) { var errorMessage = string.Join(' ', ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage)); if (id.HasValue) { return(RedirectToAction("Edit", "Notes", new { id }).WithDanger("Validation error!", errorMessage)); } else { return(RedirectToAction("Add", "Notes").WithDanger("Validation error!", errorMessage)); } } if (id.HasValue) { var success = _noteService.UpdateNote(model); if (!success) { return(UserFriendlyNotFoundError($"Could not update a note with id {id}!")); } return(RedirectToAction("Index", "Notes").WithSuccess("Success!", $"Note {id} has been updated.")); } else { id = _noteService.AddNote(model); return(RedirectToAction("Index", "Notes").WithSuccess("Success!", $"Note {id} has been created.")); } }
public IActionResult Post([FromBody] Note note) { _noteService.AddNote(note); return(StatusCode(StatusCodes.Status201Created, "Note created!")); }
public void Post([FromBody] NoteModel model) { model.UserId = GetAuthorizedUserId(); _noteService.AddNote(model); }