public ActionResult Create(EditNoteModel model) { var file = new File() { Name = model.File.FileName, Content = model.File.InputStream.ToByteArray(), Type = model.File.ContentType }; fileMethods.Save(file); Note newNote = new Note { Name = model.Name, Text = model.Text, Created = DateTime.Now, Changed = DateTime.Now, Author = CurrentUser, File = file }; notesMethods.Save(newNote); return(RedirectToAction("ShowNotes", "Notes")); }
public ActionResult EditNotePartial(EditNoteModel editNote) { Response.StatusCode = (int)HttpStatusCode.BadRequest; if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors) .Select(e => e.ErrorMessage).ToList(); return(Json(new { errors = errors })); } var note = notesRep.Load(editNote.Id); if (note == null || note.User.Login != User.Identity.Name) { return(Json(new { errors = new List <string>() { { "Заметка не найдена" } } })); } Response.StatusCode = (int)HttpStatusCode.OK; note.Text = editNote.Text; note.Status = editNote.Status; notesRep.Save(note); return(PartialView(editNote)); }
public ActionResult EditNote(int id) { ViewBag.Class = "white-nav"; //DropDown var cat = db.NoteCategories.Where(x => x.IsActive == true).ToList(); var typ = db.NoteTypes.Where(x => x.IsActive == true).ToList(); var cnt = db.Countries.Where(x => x.IsActive == true).ToList(); //Auth USer var user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name); //Note Detail var note = db.SellerNotes.Where(x => x.ID == id && x.SellerID == user.ID && x.Status == 1).FirstOrDefault(); var FileNote = db.SellerNotesAttachements.Where(x => x.NoteID == note.ID).ToList(); string path = ""; foreach (var item in FileNote) { path = path + item.FileName + ", "; } if (note == null) { return(Content("You can't have access to this file")); } EditNoteModel viewModel = new EditNoteModel(); viewModel.NoteCategoryList = cat; viewModel.NoteTypeList = typ; viewModel.CountryList = cnt; viewModel.Title = note.Title; viewModel.Category = note.Category; viewModel.NoteType = note.NoteType; viewModel.NumberofPages = note.NumberofPages; viewModel.Description = note.Description; viewModel.Country = note.Country; viewModel.UniversityName = note.UniversityName; viewModel.Course = note.Course; viewModel.CourseCode = note.CourseCode; viewModel.Professor = note.Professor; viewModel.IsPaid = note.IsPaid; viewModel.SellingPrice = note.SellingPrice; viewModel.DpPathName = note.DisplayPicture; viewModel.NpPathName = note.NotesPreview; ViewBag.ImageName = Path.GetFileName(note.DisplayPicture); ViewBag.PreviewName = Path.GetFileName(note.NotesPreview); ViewBag.FileName = path; return(View(viewModel)); }
public ActionResult Edit(EditNoteModel model) { var note = notesMethods.Load(model.NoteId); note.Name = model.Name; note.Text = model.Text; note.Changed = DateTime.Now; notesMethods.Save(note); return(RedirectToAction("ShowNotes", "Notes")); }
public ActionResult Edit(long id) { var note = notesMethods.Load(id); var model = new EditNoteModel { NoteId = note.NoteId, Name = note.Name, Text = note.Text, Changed = note.Changed, Created = note.Created, }; return(View(model)); }
public ActionResult EditNotePartial(long id) { var note = notesRep.Load(id); if (note == null || note.User.Login != User.Identity.Name) { return(HttpNotFound()); } var editNoteModel = new EditNoteModel() { Id = note.Id, Title = note.Title, Text = note.Text, Status = note.Status }; return(PartialView(editNoteModel)); }
public ActionResult Edit(int id) { var db = new SportNotesDbContext(); var note = db.Notes .Where(x => x.Id == id) .FirstOrDefault(); var editNote = new EditNoteModel() { Id = note.Id, Date = note.Date, Content = note.Content, Comment = note.Comment }; return(View(editNote)); }
public ActionResult Edit(EditNoteModel model) { if (ModelState.IsValid) { using (var db = new SportNotesDbContext()) { var note = db.Notes.Find(model.Id); if (note == null) { return(HttpNotFound()); } note.Content = model.Content; note.Comment = model.Comment; db.SaveChanges(); } return(RedirectToAction("Details", new { id = model.Id })); } return(View(model)); }
public async Task <IActionResult> EditAsync([FromRoute] Guid id, [FromBody] EditNoteModel model) { await _mediator.Send(new EditNoteCommand(id, model.Title, model.Content, model.Comment)); return(Ok()); }
public ActionResult EditNote(EditNoteModel viewModel, string Command) { ViewBag.Class = "white-nav"; User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name); var note = db.SellerNotes.Where(x => x.ID == viewModel.ID && x.Status == 1 && x.SellerID == user.ID).FirstOrDefault(); var AttachFile = db.SellerNotesAttachements.Where(x => x.NoteID == note.ID).ToList(); if (user != null && ModelState.IsValid) { note.Title = viewModel.Title; note.Status = Command == "Save" ? 1 : 2; note.Category = viewModel.Category; note.NoteType = viewModel.NoteType; note.NumberofPages = viewModel.NumberofPages; note.Description = viewModel.Description; note.UniversityName = viewModel.UniversityName; note.Country = viewModel.Country; note.Course = viewModel.Course; note.CourseCode = viewModel.CourseCode; note.Professor = viewModel.Professor; note.IsPaid = viewModel.IsPaid; note.SellingPrice = viewModel.SellingPrice; note.ModifiedDate = DateTime.Now; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); if (viewModel.DisplayPicture != null) { string FileNameDelete = System.IO.Path.GetFileName(note.DisplayPicture); string PathImage = Request.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/" + FileNameDelete); FileInfo file = new FileInfo(PathImage); if (file.Exists) { file.Delete(); } string displaypicturefilename = Path.GetFileName(viewModel.DisplayPicture.FileName); string displaypicturepath = "~/Members/" + note.SellerID + "/" + note.ID + "/"; string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename); note.DisplayPicture = displaypicturepath + displaypicturefilename; viewModel.DisplayPicture.SaveAs(displaypicturefilepath); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); } if (viewModel.NotesPreview != null) { string FileNameDelete = System.IO.Path.GetFileName(note.NotesPreview); string PathPreview = Request.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/" + FileNameDelete); FileInfo file = new FileInfo(PathPreview); if (file.Exists) { file.Delete(); } string notespreviewfilename = Path.GetFileName(viewModel.NotesPreview.FileName); string notespreviewpath = "~/Members/" + note.SellerID + "/" + note.ID + "/"; string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename); note.NotesPreview = notespreviewpath + notespreviewfilename; viewModel.NotesPreview.SaveAs(notespreviewfilepath); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); } if (viewModel.UploadNotes != null) { string deletepath = Request.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/Attachements/"); foreach (string filename in Directory.GetFiles(deletepath)) { FileInfo file = new FileInfo(filename); file.Delete(); } foreach (var item in AttachFile) { db.SellerNotesAttachements.Remove(item); db.SaveChanges(); } foreach (HttpPostedFileBase file in viewModel.UploadNotes) { if (file != null) { string notesattachementfilename = System.IO.Path.GetFileName(file.FileName); string notesattachementpath = "~/Members/" + note.SellerID + "/" + note.ID + "/Attachements/"; string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename); file.SaveAs(notesattachementfilepath); SellerNotesAttachement notesattachements = new SellerNotesAttachement { NoteID = viewModel.ID, FileName = notesattachementfilename, FilePath = notesattachementpath + notesattachementfilename, CreatedDate = DateTime.Now, CreatedBy = user.ID, ModifiedDate = DateTime.Now, ModifiedBy = user.ID, IsActive = true }; db.SellerNotesAttachements.Add(notesattachements); db.SaveChanges(); } } } return(RedirectToAction("Index", "SellNote")); } return(View()); }
public void Post(EditNoteModel edit) { NotesProvider.EditNote(User.Identity.GetUserId(), edit.name, edit.oldtext, edit.newtext); }