public ActionResult Edit(int NoteID)
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Authentication", new { ReturnUrl = @"/NoteActions/Edit/" + NoteID }));
            }

            int UserID = Convert.ToInt32(User.Identity.Name);

            NoteModel Nm = NotesRepository.GetNoteDetailsById(NoteID);

            if ((Nm.Status != 0) || Nm.SellerID != UserID)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, "You are not allowed to edit this note."));
            }

            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;
            return(View("~/Views/RegisteredUser/AddNotes.cshtml", Nm));
        }
Ejemplo n.º 2
0
        public ActionResult SearchNotes()
        {
            ViewBag.Title = "SearchNotes";

            if (Request.IsAuthenticated && Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Authentication"));
            }
            else if (Request.IsAuthenticated)
            {
                ViewBag.Authorized = true;
            }


            SearchNotesModel FilterData = new SearchNotesModel();

            FilterData.Type       = NotesFilters.Types();
            FilterData.Category   = NotesFilters.Categories();
            FilterData.Country    = NotesFilters.Countries();
            FilterData.Rating     = NotesFilters.Ratings();
            FilterData.University = NotesFilters.Universities();
            FilterData.Course     = NotesFilters.Courses();
            ViewBag.FilterData    = FilterData;

            ListNotes Ln = NotesRepository.GetAllAvailableNotes(new NoteModel()
            {
                IsItSearchAndFilter = false
            });

            ViewBag.LoadAjaxJS = true;
            ViewBag.NotesData  = Ln;
            return(View());
        }
        public ActionResult AddNotes()
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Authentication", new { ReturnUrl = "/RegisteredUser/AddNotes" }));
            }

            ViewBag.Title                = "AddNotes";
            ViewBag.Authorized           = true;
            ViewBag.LoadValidationScript = true;
            SearchNotesModel FilterData = new SearchNotesModel();

            FilterData.Type     = NotesFilters.Types();
            FilterData.Category = NotesFilters.Categories();
            FilterData.Country  = NotesFilters.Countries();
            ViewBag.FilterData  = FilterData;

            return(View());
        }
        public ActionResult AddNotes(NoteModel Nm, string SaveOrPublish)
        {
            ViewBag.Title                = "AddNotes";
            ViewBag.Authorized           = true;
            ViewBag.LoadValidationScript = true;

            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Authentication", new { ReturnUrl = "/RegisteredUser/AddNotes" }));
            }

            SearchNotesModel FilterData = new SearchNotesModel();

            FilterData.Type     = NotesFilters.Types();
            FilterData.Category = NotesFilters.Categories();
            FilterData.Country  = NotesFilters.Countries();
            ViewBag.FilterData  = FilterData;


            //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)
                {
                    ModelState.AddModelError("NotesFiles", "Make sure you have uploaded PDF file(s) that are under 30MBs");
                }
                else if (Path.GetExtension(file.FileName).ToLower() != ".pdf")
                {
                    ModelState.AddModelError("NotesFiles", "Only PDF file(s) are allowed.");
                }
                if (file != null)
                {
                    NoteSize += file.ContentLength;
                }
            }
            if (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(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(Nm));
            }

            ViewBag.Title                = "AddNotes";
            ViewBag.Authorized           = true;
            ViewBag.LoadValidationScript = true;
            string UID = User.Identity.Name;

            int result = NotesRepository.AddNote(Nm, Convert.ToInt32(UID), Server.MapPath("~"));

            if (result < 1)
            {
                ViewBag.Message = "Adding/Editing note didnt go as expected please try again.";
                return(View(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"));
        }