// setup test
        public NoteRepositoryTest() : base()
        {
            _noteRepository = new NoteRepository(_landmarkRemarkContext);
            // need to add owwner first to get userId

            _testNote.UserId  = _addedOwnerId;
            _testNote2.UserId = _addedOwnerId;
            //
            var addedNote = _noteRepository.Add(_testNote);

            _noteRepository.Add(_testNote2);
            _addedTestNoteId = addedNote.Id;
        }
Esempio n. 2
0
        [Authorize] // 스팸 글 때문에 추가
        public async Task <IActionResult> Create(
            Note model, ICollection <IFormFile> files)
        {
            //파일 업로드 처리 시작
            string fileName = String.Empty;
            int    fileSize = 0;

            var uploadFolder = Path.Combine(_environment.WebRootPath, "files");

            foreach (var file in files)
            {
                if (file.Length > 0)
                {
                    fileSize = Convert.ToInt32(file.Length);
                    // 파일명 중복 처리
                    fileName = Dul.FileUtility.GetFileNameWithNumbering(
                        uploadFolder, Path.GetFileName(
                            ContentDispositionHeaderValue.Parse(
                                file.ContentDisposition).FileName.Trim('"')));
                    // 파일 업로드
                    using (var fileStream = new FileStream(
                               Path.Combine(uploadFolder, fileName), FileMode.Create))
                    {
                        await file.CopyToAsync(fileStream);
                    }
                }
            }

            Note note = new Note();

            note.Name     = model.Name;
            note.Email    = Dul.HtmlUtility.Encode(model.Email);
            note.Homepage = model.Homepage;
            //note.Title    = Dul.HtmlUtility.Encode(model.Title);
            note.Title    = model.Title;
            note.Content  = model.Content;
            note.FileName = fileName;
            note.FileSize = fileSize;
            note.Password =
                (new Dul.Security.CryptorEngine()).EncryptPassword(model.Password);
            note.PostIp =
                HttpContext.Connection.RemoteIpAddress.ToString(); // IP 주소
            note.Encoding = model.Encoding;

            _repository.Add(note); // 데이터 저장

            // 데이터 저장 후 리스트 페이지 이동시 toastr로 메시지 출력
            TempData["Message"] = "데이터가 저장되었습니다.";

            return(RedirectToAction("Index")); // 저장 후 리스트 페이지로 이동
        }
Esempio n. 3
0
        public string Get(string setting)
        {
            switch (setting)
            {
            case "init note":
                _noteRepository.RemoveAll();
                _noteRepository.Add(new Note()
                {
                    Id        = "1", Body = "Test note 1",
                    CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now, UserId = 1
                });
                _noteRepository.Add(new Note()
                {
                    Id        = "2", Body = "Test note 2",
                    CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now, UserId = 1
                });
                _noteRepository.Add(new Note()
                {
                    Id        = "3", Body = "Test note 3",
                    CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now, UserId = 2
                });
                _noteRepository.Add(new Note()
                {
                    Id        = "4", Body = "Test note 4",
                    CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now, UserId = 2
                });
                break;

            case "init stuff":
                _stuffRepository.RemoveAll();
                _stuffRepository.Add(new StuffItem
                {
                    Name        = "name1",
                    Description = "d1",
                    Tags        = new List <TagItem> {
                        new TagItem {
                            Id = 1, Value = "2"
                        }
                    }
                });
                break;

            default:
                return("Unknown");
            }

            return("Done");
        }
            public async Task <IResult> Handle(CreateNoteCommand request, CancellationToken cancellationToken)
            {
                int userId = 0;

                Int32.TryParse(_httpContextAccessor.HttpContext?.User.Claims.FirstOrDefault(x => x.Type.EndsWith("nameidentifier"))?.Value, out userId);

                if (userId == 0)
                {
                    return(new ErrorResult(Messages.UserNotFound));
                }

                var isThereNoteRecord = _noteRepository.Query().Any(u => u.MovieId == request.MovieId && u.UserId == userId);

                if (isThereNoteRecord == true)
                {
                    return(new ErrorResult(Messages.NoteAllreadyExistForUser));
                }

                var addedNote = new Note
                {
                    MovieId = request.MovieId,
                    Content = request.Content,
                    Score   = request.Score,
                    UserId  = userId
                };

                _noteRepository.Add(addedNote);
                await _noteRepository.SaveChangesAsync();

                return(new SuccessResult(Messages.Added));
            }
 private void AddNote(string obj, int i)
 {
     NoteRepository.Add(new NoteDTO()
     {
         Name = obj, FolderId = i
     });
 }
Esempio n. 6
0
 public ActionResult Add(AddModel model)
 {
     if (model.File != null)
     {
         string pathFile = "/Files/" + User.Identity.Name + "/";
         string pathIco  = "/Files/Ico/" + User.Identity.Name + "/";
         if (!Directory.Exists(Server.MapPath(pathFile)))
         {
             Directory.CreateDirectory(Server.MapPath(pathFile));
         }
         if (!Directory.Exists(Server.MapPath(pathIco)))
         {
             Directory.CreateDirectory(Server.MapPath(pathIco));
         }
         string filename = Path.GetFileName(model.File.FileName);
         model.File.SaveAs(Server.MapPath(pathFile + filename));
         int    author        = _authProvider.SearchUser(User.Identity.Name);
         string path          = pathFile + filename;
         Icon   extractedIcon = Icon.ExtractAssociatedIcon(Server.MapPath(pathFile + filename));
         string icostr        = filename;
         string v             = Path.GetExtension(filename);
         icostr = icostr.Replace(v, "") + ".jpg";
         Bitmap bitmap = extractedIcon.ToBitmap();
         bitmap.Save(Server.MapPath(pathIco + icostr));
         icostr = "/Files/Ico/" + User.Identity.Name + "/" + icostr;
         _noteRepositoty.Add(model.Name, author, icostr, path, model.Published, model.Text, model.Tag);
     }
     return(RedirectToAction("MyIndex"));
 }
Esempio n. 7
0
        public NoteDTO Create(Guid Id, string title, string content, string keyWordsSummary)
        {
            var note = new Note(Id, title, content, keyWordsSummary);

            _noteRepository.Add(note);
            return(_mapper.Map <NoteDTO>(note));
        }
Esempio n. 8
0
 public void Post([FromBody] string value)
 {
     _noteRepository.Add(new Note()
     {
         Body = value, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now
     });
 }
Esempio n. 9
0
        public ActionResult <NoteCreationViewModel> Post([FromBody] NoteUpdateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var ownerId      = HttpContext.User.Identity.Name;
            var creationTime = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds();
            var noteId       = Guid.NewGuid().ToString();
            var note         = new Note
            {
                Id           = noteId,
                Title        = model.Title,
                Content      = model.Content,
                CreationTime = creationTime,
                LastEditTime = creationTime,
                OwnerId      = ownerId,
            };

            _noteRepository.Add(note);
            _noteRepository.Commit();

            return(new NoteCreationViewModel
            {
                NoteId = noteId
            });
        }
Esempio n. 10
0
        public IActionResult CreateNote([FromBody] NoteForCreation noteForCreation)
        {
            if (noteForCreation == null)
            {
                return(BadRequest("Posted data is invalid"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var note = Mapper.Map <Note>(noteForCreation);

            _noteRepository.Add(note);

            if (!_noteRepository.Save())
            {
                return(StatusCode(500, "Failed to handle your request. Unknown errors."));
            }

            var createNoteModel = Mapper.Map <NoteModel>(note);

            return(CreatedAtRoute("GetNote", new { id = createNoteModel.Id }, createNoteModel));
        }
Esempio n. 11
0
        public NoteDto Create(Guid Id, string title, string content)
        {
            var note = new Note(Id, title, content);

            _noteReposiotry.Add(note);
            return(_mapper.Map <NoteDto>(note));
        }
Esempio n. 12
0
        public IActionResult Create(NoteCreateViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string uniqueFileName = ProcessUploadedFile(model);

                    Note newNote = new Note()
                    {
                        Content   = model.Content,
                        Author    = model.Author,
                        PhotoPath = uniqueFileName,
                    };

                    _noteRepository.Add(newNote);
                    return(RedirectToAction("details", new { id = newNote.ID }));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View());
        }
Esempio n. 13
0
        public async Task Handle(SaveNoteCommand command)
        {
            var model = command.Model;

            if (model.Id == Guid.Empty)
            {
                throw new InvalidOperationException($"Model '{model.Title}' has empty id");
            }

            var note = await noteRepository.Get(model.Id);

            if (note != null)
            {
                note.MoveToFolder(model.FolderId);
                note.ChangeTitle(model.Title);
                note.ChangeText(model.Text);
                note.ChangeReminder(model.Reminder?.ToEntity());
                note.SetFlag(model.IsFlagged);

                await noteRepository.Update(note);

                notificationService.Reschedule(note);
                eventBus.Publish(new NoteUpdatedEvent(model));
            }
            else
            {
                note = model.ToEntity();
                await noteRepository.Add(note);

                notificationService.Schedule(note);
                eventBus.Publish(new NoteAddedEvent(model));
            }
        }
Esempio n. 14
0
        public Task SaveNoteAsync(int userId, NoteModel note)
        {
            var entity = ToEntity(note);

            entity.UserId = userId;
            _noteRepository.Add(entity);
            return(Task.CompletedTask);
        }
        public override void OnCreate()
        {
            base.OnCreate();

            //NoteRepository = new AdoNoteRepository();
            NoteRepository = new XmlNoteRepository();
            NoteRepository.Add("Test", "Post");
        }
        public IActionResult Post([FromBody] Note note)
        {
            // this code here is effectively automatic because of ApiControllerAttribute
            // if (!ModelState.IsValid) return BadRequest(ModelState);

            _noteRepository.Add(note);
            // id is now set
            return(CreatedAtAction(nameof(GetById), new { id = note.Id }, note));
        }
Esempio n. 17
0
        public async Task Add(Note note)
        {
            if (!ExecuteValidation(new NoteValidation(), note))
            {
                return;
            }

            await _noteRepository.Add(note);
        }
Esempio n. 18
0
        public void AddNote(NoteModel noteModel)
        {
            User userDb = ValidateNoteModel(noteModel);

            Note noteForDb = noteModel.ToNote();

            //noteForDb.User = userDb;
            _noteRepository.Add(noteForDb);
        }
        public IActionResult Post([FromBody] Note value)
        {
            if (value == null)
            {
                return(BadRequest());
            }
            var createdNote = _noteRepository.Add(value);

            return(CreatedAtRoute("GetNote", new { id = createdNote.Id }, createdNote));
        }
Esempio n. 20
0
        public IActionResult Post(Note note)
        {
            var currentUserProfile = GetCurrentUserProfile();

            note.UserProfileId = currentUserProfile.Id;
            note.CreateDate    = DateTime.Now;

            _noteRepository.Add(note);
            return(CreatedAtAction(nameof(Get), new { id = note.Id }, note));
        }
Esempio n. 21
0
        // New note added action
        private void OnNewNoteAdded(GenericMessage <NoteViewModel> msg)
        {
            int  count = Notes.Count + 1;
            Note note  = new Note {
                Title = "Title " + count, Text = "Text " + count
            };

            _localNoteRepository.Add(note);
            Notes.Add(new NoteViewModel(note));
        }
Esempio n. 22
0
        public ActionResult Post([FromBody] Note note)
        {
            Note insertedNote = noteRepository.Add(note);

            if (insertedNote != null)
            {
                return(new CreatedResult("api/post", insertedNote));
            }
            return(new BadRequestObjectResult("Something went wrong"));
        }
Esempio n. 23
0
        public void AddNote(NotesViewModel.Note note)
        {
            Ensure.NotNull(note, "note");

            Mapper.CreateMap <NotesViewModel.Note, Note>();
            var newNote = Mapper.Map <NotesViewModel.Note, Note>(note);

            _noteRepository.Add(newNote);
            _unitOfWork.Commit();
        }
Esempio n. 24
0
        private void createNoteBtn_Click(object sender, EventArgs e)
        {
            var dialog = new NoteDialog(new Note(), false);
            var result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                _noteRepo.Add(dialog.Item);
                reloadNotes();
            }
        }
Esempio n. 25
0
        public IActionResult Add(NoteCreateUpdateDto note)
        {
            if (!noteValidator.ValidateAdd(note))
            {
                return(new BadRequestResult());
            }

            noteRepository.Add(note);

            return(new NoContentResult());
        }
Esempio n. 26
0
        [HttpPost]//Method to take in the new note for the donor
        public ActionResult AddNote(int id, string note)
        {
            NOTES notes = new NOTES();

            notes.DonorId  = id;
            notes.Note     = note;
            notes.DateMade = DateTime.Now;
            ntRepo.Add(notes);

            return(RedirectToAction("Details", new { id }));
        }
Esempio n. 27
0
        public override void Add(NoteDto dto)
        {
            var note = _mapper.Map <Note>(dto);

            _noteRepository.Add(note);
            _noteRepository.UnitOfWork.SaveChanges();

            _noteRepository.UpdateNoteTags(note.Id, dto.NoteTags.Select(ntDto => ntDto.Title));
            _noteRepository.UnitOfWork.SaveChanges();

            dto.Id = note.Id;
        }
Esempio n. 28
0
        public async Task <IActionResult> Add(NoteModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            ViewBag.CategoriesName = categories;
            ViewBag.ManagerNames   = managers;

            await _noteRepo.Add(model);

            return(RedirectToRoute(new { controller = "Note", action = "GetAllNotes" }));
        }
Esempio n. 29
0
        public async Task <Result> AddAsync(NoteAdd note)
        {
            var n      = note.CreateNote();
            var result = await Task.Run(() =>
            {
                var result = new Result();
                var c      = _contactRepository.Get(n.ContactId);
                if (c == null)
                {
                    result.IsError   = true;
                    result.Message   = "Contact does not exist";
                    result.StatuCode = 400;
                }
                else
                {
                    _noteRepository.Add(n);
                    _noteRepository.Complete();
                }
                return(result);
            });

            return(result);
        }
        public NoteModel Add(NoteModel entity)
        {
            try
            {
                _repo.Add(_mapper.Map <Note>(entity));

                UoW.Commit();
                return(entity);
            }
            catch (Exception)
            {
                UoW.RollBack();
                return(null);
            }
        }