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() }); }
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; }
public void UpdateNote(Note note) { context.Entry(note).State = EntityState.Modified; }
public void InsertNote(Note note) { context.Notes.Add(note); }