public async Task <IActionResult> Create(CreateNoteViewModel noteViewModel) { ModelState.Remove("note.user"); if (ModelState.IsValid) { if (noteViewModel.ToUserId != null) { // find matching user for SalesRep in system ApplicationUser ToUser = _context.Users.Single(u => u.Id == noteViewModel.ToUserId); // store the sales rep on the store noteViewModel.Note.ToUser = ToUser; } // get current user ApplicationUser user = await GetCurrentUserAsync(); // add current user noteViewModel.Note.User = user; _context.Add(noteViewModel.Note); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Edit(int id, CreateNoteViewModel noteViewModel) { if (id != noteViewModel.Note.NoteId) { return(NotFound()); } // remove user from model state ModelState.Remove("note.User"); if (ModelState.IsValid) { // attach the user object for the user that was selected as the recipient noteViewModel.Note.ToUser = await _context.Users.SingleOrDefaultAsync(u => u.Id == noteViewModel.ToUserId); try { _context.Update(noteViewModel.Note); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NoteExists(noteViewModel.Note.NoteId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "Home")); } return(View(noteViewModel.Note)); }
// GET Notes Edit public ActionResult Edit(int?id) { CreateNoteViewModel note = null; if (Request.Cookies["login"] != null) { User usr = userRepository.GetByID(Convert.ToInt64(Request.Cookies["login"].Value)); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } note = Mapper.Map <Note, CreateNoteViewModel>(noteRepository.GetByID(id)); if (note == null) { return(HttpNotFound()); } note.Label = EncryptDecrypt.DecryptData(note.Label, usr.Pass); note.Body = EncryptDecrypt.DecryptData(note.Body, usr.Pass); } else { ViewBag.ErrorLogin = "******"; return(View("../Users/Login")); } return(View(note)); }
public async Task <IActionResult> CreateNote(int id, [Bind("ProjectId,Title,Notes")] CreateNoteViewModel createNoteViewModel) { if (createNoteViewModel.ProjectId < 0) { return(NotFound()); } if (ModelState.IsValid) { try { var asset = new Note(); asset.Title = createNoteViewModel.Title; asset.Notes = createNoteViewModel.Notes; // get IP string accessIpAddress = HttpContext?.Connection?.RemoteIpAddress?.ToString(); await _assetService.AddAssetToProjectAsync(createNoteViewModel.ProjectId, asset, accessIpAddress); } catch (DbUpdateConcurrencyException) { throw; } return(RedirectToAction(nameof(Details), new { id = createNoteViewModel.ProjectId })); } return(RedirectToAction(nameof(Index))); }
private Note MapViewModelToNote(CreateNoteViewModel viewModel, Note note) { if (viewModel.Photos != null) { var photosContent = new List <string>(); foreach (var formFile in viewModel.Photos) { using (var ms = new MemoryStream()) { formFile.CopyTo(ms); var fileBytes = ms.ToArray(); photosContent.Add(Convert.ToBase64String(fileBytes)); } } var photos = new List <Photo>(); for (int i = 0; i < viewModel.Photos.Count(); i++) { var photo = new Photo { Name = viewModel.Photos.ElementAt(i).FileName, Image = photosContent.ElementAt(i), Note = note }; photos.Add(photo); } note.Photos = photos; } return(note); }
public ActionResult CreateNote(int meetid) { CreateNoteViewModel model = new CreateNoteViewModel(); model.MeetId = meetid; return(View(model)); }
public async Task <IViewComponentResult> InvokeAsync() { // get current user var user = await GetCurrentUserAsync(); // populate dropdown of users ViewBag.Users = _context.Users.OrderBy(u => u.FirstName) .Select(u => new SelectListItem() { Text = $"{ u.FirstName} { u.LastName}", Value = u.Id }).ToList(); // create a new Notes view model instance var NotesViewModel = new CreateNoteViewModel() { // attach current user to view model CurrentUser = user }; // get notes from the database NotesViewModel.UserNotes = await GetNotesAsync(); // return flags return(View(NotesViewModel)); }
public ActionResult Create(CreateNoteViewModel model) { if (Request.Cookies["login"] != null) { User usr = userRepository.GetByID(Convert.ToInt64(Request.Cookies["login"].Value)); if (ModelState.IsValid) { var note = Mapper.Map <CreateNoteViewModel, Note>(model); note.CreatedDate = DateTime.Now; note.EditedDate = DateTime.Now; note.UserId = usr.UserId; note.Label = EncryptDecrypt.EncryptData(note.Label, usr.Pass); note.Body = EncryptDecrypt.EncryptData(note.Body, usr.Pass); noteRepository.Insert(note); noteRepository.Save(); return(RedirectToAction("Index")); } } else { ViewBag.ErrorLogin = "******"; return(View("../Users/Login")); } return(View(model)); }
public IActionResult Create(CreateNoteViewModel model) { var note = this.mapper.Map <Note>(model); this.notesService.CreateNote(note, this.User.Identity.Name); return(this.RedirectToAction(nameof(this.All))); }
public IHttpActionResult CreateNote([FromBody] CreateNoteViewModel viewModel) { var note = Mapper.Map <CreateNoteViewModel, Note>(viewModel); note.User = this.CurrentLoginUser; this.noteRepository.Add(note); this.RepositoryContext.Commit(); return(this.Ok(note.ID)); }
public static CreateNoteViewModel GetNoteViewModel(Project project) { var viewModel = new CreateNoteViewModel(); viewModel.ProjectId = project.Id; viewModel.ProjectTitle = project.Title; return(viewModel); }
public CreateNoteResponse Create(CreateNoteViewModel note) { var id = _noteService.Create(note); var response = new CreateNoteResponse() { Id = id }; return(response); }
public async Task <IActionResult> Post([FromBody] CreateNoteViewModel model) { //This could be added into global filter if null model validation is being checked at multiple places if (model == null) { return(BadRequest()); } var userId = int.Parse(User.Identity.Name); var result = await _mediator.Send(new CreateNoteCommand { UserId = userId, Text = model.Text, Latitude = model.Latitude, Longitude = model.Longitude }); return(Ok(result)); }
public void CreateNote(CreateNoteViewModel model) { if (ModelState.IsValid) { string uid = User.Identity.GetUserId(); List <Folder> fl = Load(uid, ""); Folder f = new Folder(); foreach (Folder x in fl) { if (x.Name == model.Name && x.UserID.GetDirectReference() == uid) { Debug.WriteLine(x.ID); f = x; break; } } Note n = new Note(); SqlCommand command = new SqlCommand( "INSERT INTO Note (ID, Title, Content, FolderID, UserID) " + "VALUES (@id, @title, @content, @folderid, @userid)"); SqlParameter NID = new SqlParameter { ParameterName = "@id", Value = n.ID }; SqlParameter TTL = new SqlParameter { ParameterName = "@title", Value = model.Title }; SqlParameter CTT = new SqlParameter { ParameterName = "@content", Value = n.Content }; SqlParameter FID = new SqlParameter { ParameterName = "@folderid", Value = f.ID.GetDirectReference() }; SqlParameter UID = new SqlParameter { ParameterName = "@userid", Value = uid }; command.Parameters.Add(NID); command.Parameters.Add(TTL); command.Parameters.Add(CTT); command.Parameters.Add(FID); command.Parameters.Add(UID); Utility.Constants.CallDB(command); } }
// GET: Notes/Create public IActionResult Create() { CreateNoteViewModel CreateNoteViewModel = new CreateNoteViewModel(); ViewBag.Users = _context.Users.OrderBy(u => u.FirstName) .Select(u => new SelectListItem() { Text = $"{ u.FirstName} { u.LastName}", Value = u.Id }).ToList(); return(View(CreateNoteViewModel)); }
public IActionResult Create(CreateNoteViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var noteToAdd = _mapper.Map <Note>(model); _noteService.Create(noteToAdd); return(RedirectToAction(NoteActions.GetNotes, ControllerNames.Note)); }
public async Task <IActionResult> CreateModalAsync(Guid uid) { if (uid == Guid.Empty) { return(Json(new { message = $"{GlobalConstants.ERROR_ACTION_PREFIX} find {ENTITY_NAME}." })); } CreateNoteViewModel _Model = new CreateNoteViewModel { EquipmentUID = uid }; return(PartialView("_CreateNote", _Model)); }
async void OnItemTapped(object sender, ItemTappedEventArgs e) { Note tappedNoteItem = e.Item as Note; var createNoteVM = new CreateNoteViewModel(tappedNoteItem); var createNotePage = new CreateNotePage(); createNotePage.BindingContext = createNoteVM; await Navigation.PushAsync(createNotePage); System.Diagnostics.Debug.WriteLine("SELECTED : " + tappedNoteItem.ID); }
public void CreateNoteTest() { var notesController = new NotesController(MockRepositoryContext.Object, mockNoteRepository.Object); var createNoteViewModel = new CreateNoteViewModel { Content = "Test Content", Title = "Test", Weather = "Sunny" }; notesController.CreateNote(createNoteViewModel); Assert.AreEqual(3, notes.Count); Assert.IsNotNull(notes[0].User); Assert.AreEqual(CurrentLoginUser, notes[0].User); }
//public ActionResult Edit([Bind(Include = "NoteId,CreatedDate,EditedDate,Label,Body")] Note note) public ActionResult Edit(CreateNoteViewModel model) { if (ModelState.IsValid) { Note note = Mapper.Map <CreateNoteViewModel, Note>(model); Note nt = noteRepository.GetByID(note.NoteId); nt.EditedDate = DateTime.Now; nt.Label = note.Label; nt.Body = note.Body; noteRepository.Update(nt); noteRepository.Save(); return(RedirectToAction("Index")); } return(View(model)); }
public void CreateNoteTest() { var notesController = new NotesController(MockRepositoryContext.Object, mockNoteRepository.Object); var createNoteViewModel = new CreateNoteViewModel { Content = "Test Content", Title = "Test", Weather = "Sunny" }; notesController.CreateNote(createNoteViewModel); Assert.AreEqual(3, notes.Count); Assert.IsNotNull(notes[0].User); Assert.AreEqual(CurrentLoginUser, notes[0].User); }
//public ActionResult Create([Bind(Include = "NoteId,CreatedDate,EditedDate,Label,Body,UserId")] Note note) public ActionResult Create(CreateNoteViewModel model) { if (ModelState.IsValid) { User usr = userRepository.GetByID(Convert.ToInt64(Request.Cookies["login"].Value)); var note = Mapper.Map <CreateNoteViewModel, Note>(model); note.CreatedDate = DateTime.Now; note.EditedDate = DateTime.Now; note.UserId = usr.UserId; noteRepository.Insert(note); noteRepository.Save(); return(RedirectToAction("Index")); } return(View(model)); }
// GET: Create public ActionResult Create() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new CategoryService(userId); var categories = service.GetCategories(); var viewModel = new CreateNoteViewModel(); viewModel.Categories = categories.OrderBy(n => n.Name).Select(c => new SelectListItem { Text = c.Name, Value = c.CategoryId.ToString() }); return(View(viewModel)); }
public async Task <IActionResult> Create(CreateNoteViewModel noteViewModel) { try { if (ModelState.IsValid) { var note = _mapper.Map <NoteModel>(noteViewModel); await _notesService.CreateNote(note); return(RedirectToAction("Index")); } } catch { } return(View("Index", noteViewModel)); }
public async Task <IActionResult> Create(CreateNoteViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var note = _config.Map <CreateNoteViewModel, Note>(model); note = MapViewModelToNote(model, note); await _repository.CreateAsync(note); await _repository.SaveAsync(); return(RedirectToAction("Index")); }
public object CreateNote(CreateNoteViewModel createNoteViewModel) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseResponse(ResponseStatus.ValidationError.ToString(), ModelState.Values.ToList()[0].Errors[0].ErrorMessage))); } CurrentUserInfo currentUserInfo = _tokenHelper.GetUserInfo(); NoteData NoteData = CreateNoteViewModel.GetNoteData(currentUserInfo.Id, createNoteViewModel); _NoteLogic.Add(NoteData); return(Request.CreateResponse(HttpStatusCode.OK, new BaseResponse(ResponseStatus.Success.ToString(), ResponseMessagesModel.Success))); }
public void CreatePostMethodSavesNoteSuccessfully() { var testStore = new List <Note>(); var userManager = TestUserManager <AppUser>(); var repoMock = new Mock <IRepository <Note> >(); repoMock.Setup(x => x.CreateAsync(It.IsAny <Note>())).Callback((Note item) => { testStore.Add(item); }); repoMock.Setup(x => x.SaveAsync()).Callback(() => { }); var repository = repoMock.Object; var note = new CreateNoteViewModel { Description = "test note" }; var noteController = new NoteController(userManager, repository); var result = noteController.Create(note); Assert.Single(testStore); }
public ActionResult CrNote(CreateNoteViewModel model, int meetid) { Note NewNote = new Note(); var usi = User.Identity.GetUserId(); var us = db.Users.Where(u => u.Id == usi).Single(); NewNote.Author = us; Meeting met = new Meeting(); met = db.Meetings.Where(m => m.MId == meetid).Single(); NewNote.Meeting = met; NewNote.Text = model.Text; db.Notes.Add(NewNote); met.Notes.Add(NewNote); us.Notes.Add(NewNote); db.Meetings.Attach(met); db.Users.Attach(us); db.SaveChanges(); return(RedirectToAction("ManageMeeting", "Meeting", new { @meetid = model.MeetId })); }
public ActionResult Create(CreateNoteViewModel model) { if (ModelState.IsValid) { var user = db.GetUserByID(GetUserId()); var note = new Note { User = user, Title = model.Title, Notebook = model.Notebook, IntervalInDays = model.IntervalInDays, DueDate = model.FirstStudiedDate.FromLocalTime(user) + TimeSpan.FromDays(1), FirstStudiedDate = model.FirstStudiedDate.FromLocalTime(user), TimeEstimate = model.TimeEstimate }; foreach (var resource in model.Resources) { if (String.IsNullOrWhiteSpace(resource.Title) && String.IsNullOrWhiteSpace(resource.Url)) { continue; } resource.Note = note; db.InsertResource(resource); } var review = new Review { Date = note.FirstStudiedDate, Note = note }; db.InsertReview(review); db.InsertNote(note); db.SaveChanges(); TempData["successMsg"] = $"Successfully created the note \"{note.Title}\"."; return(RedirectToAction("StudyList")); } TempData["errorMsg"] = "Failed. Please check the fields and try again."; return(View(model)); }
public async Task <IActionResult> CreateAsync(CreateNoteViewModel model) { if (!ModelState.IsValid) { ViewData["ErrorMessage"] = "Invalid form submission"; return(PartialView("_CreateNote", model)); } BaseResponse _Response = new BaseResponse(); model.OwnerUID = User.FindFirstValue(ClaimTypes.NameIdentifier); _Response = await __NoteManager.CreateAsync(__Mapper.Map <CreateNoteRequest>(model)); if (!_Response.Success) { ModelState.AddModelError("Error", _Response.Message); return(await CreateModalAsync(model.EquipmentUID)); } return(Json(new { success = $"{GlobalConstants.SUCCESS_ACTION_PREFIX} created {ENTITY_NAME}." })); }
// GET: Notes/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var note = await _context.Note.Include("ToUser").SingleOrDefaultAsync(m => m.NoteId == id); // create a new view model and attach the retrieved note var cnvm = new CreateNoteViewModel() { Note = note }; if (note.ToUser != null) { cnvm.ToUserId = note.ToUser.Id; } else { cnvm.ToUserId = null; } // populate dropdown of users ViewBag.Users = _context.Users.OrderBy(u => u.FirstName) .Select(u => new SelectListItem() { Text = $"{ u.FirstName} { u.LastName}", Value = u.Id }).ToList(); if (note == null) { return(NotFound()); } return(View(cnvm)); }