示例#1
0
        public ActionResult Index(Note note, HttpPostedFileBase attFile)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (note.id > 0)
                    {
                        unitOfWork.NoteRepository.UpdateNote(note);
                    }
                    else
                    {
                        unitOfWork.NoteRepository.InsertNote(note);
                    }
                    updateAttachFile(note, attFile);
                    unitOfWork.Save();
                    return RedirectToAction("Index");
                }
            }catch(DataException){
                ModelState.AddModelError("", "Unable to save changes. Try again please");
            }

            var notes = unitOfWork.NoteRepository.GetNotes();
            return View(new NoteViewModel() { noteList = notes.ToList(), note = new Note() });
        }
示例#2
0
        private void updateAttachFile(Note note,HttpPostedFileBase attFile)
        {
            if (attFile == null) return;

            List<AttachedFile> list = new List<AttachedFile>();

            var fileName = Path.GetFileName(attFile.FileName);
            fileName = fileName.Replace(" ", "");
            fileName = Regex.Replace(fileName, @"\s|\$|\#\%", "");
            var path = Path.Combine(Server.MapPath("~/App_data/uploads"), fileName);
            attFile.SaveAs(path);

            list.Add(new AttachedFile
            {
                fileName = fileName
            });

            note.AttachedFiles = list;
        }
示例#3
0
 public void UpdateNote(Note note)
 {
     context.Entry(note).State = EntityState.Modified;
 }
示例#4
0
 public void InsertNote(Note note)
 {
     context.Notes.Add(note);
 }