public IActionResult Put(int id, [FromBody] NotesModel NoteEdited) { var identity = HttpContext.User.Identity as ClaimsIdentity; var userid = identity.FindFirst(ClaimTypes.Name).Value; int Userid = Int32.Parse(userid); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { return(Ok(NotesRepository.EditNote(id, NoteEdited, Userid))); } catch (Exception ex) { return(BadRequest($"Failed: {ex}")); } }
public ActionResult Edit(int NoteID, NoteModel Nm, string SaveOrPublish) { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Authentication", new { ReturnUrl = @"/NoteActions/Edit/" + NoteID })); } SearchNotesModel FilterData = new SearchNotesModel(); FilterData.Type = NotesFilters.Types(); FilterData.Category = NotesFilters.Categories(); FilterData.Country = NotesFilters.Countries(); ViewBag.FilterData = FilterData; ViewBag.Title = "AddNotes"; ViewBag.Authorized = true; ViewBag.LoadValidationScript = true; ViewBag.Edit = true; int UserID = Convert.ToInt32(User.Identity.Name); //check uploaded files and their size if (Nm.PreviewFile != null && (Path.GetExtension(Nm.PreviewFile.FileName).ToLower() != ".pdf" || Nm.PreviewFile.ContentLength > 31457280)) { ModelState.AddModelError("PreviewFile", "Only PDF files that are under 30MBs are allowed."); } long NoteSize = 0; foreach (HttpPostedFileBase file in Nm.NotesFiles) { if (file == null) { break; } else if (Path.GetExtension(file.FileName).ToLower() != ".pdf") { ModelState.AddModelError("NotesFiles", "Only PDF file(s) are allowed."); } if (file != null) { NoteSize += file.ContentLength; } } if (Nm.NotesFiles[0] != null && NoteSize > 31457280) { ModelState.AddModelError("NotesFiles", "Combine PDF(s) size should not exceeds 30MBs"); } if (Nm.NotesCoverPage != null && !MimeMapping.GetMimeMapping(Nm.NotesCoverPage.FileName).ToLower().Contains("image")) { ModelState.AddModelError("NotesCoverPage", "Only Images are allowed."); } if (!ModelState.IsValid) { return(View("~/Views/RegisteredUser/AddNotes.cshtml", Nm)); } //0 for draft 1 for submit for review if (SaveOrPublish == "Save") { Nm.Status = 0; } else if (SaveOrPublish == "Publish") { Nm.Status = 1; } else { ViewBag.Message = "Adding / Editing note didnt go as expected please try again."; return(View("~/Views/RegisteredUser/AddNotes.cshtml", Nm)); } Nm.NoteId = NoteID; bool result = NotesRepository.EditNote(UserID, Nm, Server.MapPath("~")); if (!result) { ViewBag.Message = "Adding/Editing note didnt go as expected please try again."; return(View("~/Views/RegisteredUser/AddNotes.cshtml", Nm)); } if (SaveOrPublish == "Publish") { ViewBag.SellerName = Session["FullName"]; ViewBag.NoteName = Nm.Title; SendMail.SendEmail(new EmailModel() { EmailTo = SystemConfigData.GetSystemConfigData("AdminEmails").DataValue.Split(';'), EmailSubject = Session["FullName"].ToString() + " sent his note for review.", EmailBody = this.getHTMLViewAsString("~/Views/Email/RequestToReview.cshtml") }); TempData["Message"] = "Note has been submitted for review, we will send you mail when it gets approved."; } else { TempData["Message"] = "Note has been successfully saved in Drafts"; } return(RedirectToAction("Dashboard", "RegisteredUser")); }
public bool UpdateNote(int idNote, string title, string content) { NotesRepo.EditNote(idNote, title, content); return(true); }