Example #1
0
        public ActionResult ViewNote(int noteId)
        {
            DBEntities _db = new DBEntities();

            Models.SellerNote note = _db.SellerNotes.FirstOrDefault(x => x.ID == noteId);
            return(View(note));
        }
Example #2
0
        public ActionResult SearchNotes()
        {
            DBEntities    _db            = new DBEntities();
            var           typeList       = _db.NoteTypes.ToList();
            var           categoryList   = _db.NoteCategories.ToList();
            var           countryList    = _db.Countries.ToList();
            List <string> universityList = new List <string>();

            foreach (InitialNotesMarketplace.Models.SellerNote row in _db.SellerNotes)
            {
                if (!universityList.Contains(row.UniversityName))
                {
                    universityList.Add(row.UniversityName);
                }
            }

            List <string> courseList = new List <string>();

            foreach (InitialNotesMarketplace.Models.SellerNote row in _db.SellerNotes)
            {
                if (!courseList.Contains(row.Course))
                {
                    courseList.Add(row.Course);
                }
            }

            SearchNote searchNote = new SearchNote()
            {
                ListCategories   = categoryList,
                ListCountries    = countryList,
                ListTypes        = typeList,
                ListUniversities = universityList,
                ListCourses      = courseList
            };

            Session["searchNote"] = searchNote;
            Models.SellerNote snote = new Models.SellerNote();

            return(View(snote));
        }
Example #3
0
        public ActionResult AddNote(Note model, FormCollection collection)
        {
            bool isPaid = false;

            if (collection["sell-for"] == "paid")
            {
                isPaid = true;
            }
            User loggedInUser = (User)Session["user"];

            using (var context = new DBEntities())
            {
                Models.Extended.SellerNote newNote = model.sellerNote;

                Models.SellerNote note1 = new Models.SellerNote()
                {
                    SellerID       = loggedInUser.ID,
                    Title          = newNote.Title,
                    Status         = 7,
                    Category       = newNote.Category,
                    NoteType       = newNote.NoteType,
                    NumberOfPages  = newNote.NumberOfPages,
                    Description    = newNote.Description,
                    Country        = newNote.Country,
                    UniversityName = newNote.UniversityName,
                    Course         = newNote.Course,
                    CourseCode     = newNote.CourseCode,
                    Professor      = newNote.Professor,
                    IsPaid         = isPaid,
                    SellingPrice   = newNote.SellingPrice,
                    IsActive       = true,
                    CreatedDate    = DateTime.Now,
                    CreatedBy      = loggedInUser.ID,
                    ModifiedDate   = DateTime.Now,
                    ModifiedBy     = loggedInUser.ID
                };

                context.SellerNotes.Add(note1);
                try
                {
                    context.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            System.Diagnostics.Debug.WriteLine("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                        }
                    }
                }

                string previewPath = Server.MapPath("~/Members/" + note1.SellerID + "/" + note1.ID);

                if (!Directory.Exists(previewPath))
                {
                    Directory.CreateDirectory(previewPath);
                }

                string previewFileName         = "Preview_" + DateTime.Now.ToString("dd/MM/yyyy") + ".pdf";
                string fullPreviewFilePath     = Path.Combine(previewPath, previewFileName);
                string relativePreviewFilePath = Path.Combine("~/Members/" + note1.SellerID + "/" + note1.ID, previewFileName);
                model.sellerNote.NotesPreview.SaveAs(fullPreviewFilePath);

                var fNote = context.SellerNotes.FirstOrDefault(x => x.ID == note1.ID);
                fNote.NotesPreview = relativePreviewFilePath;

                string displayPicPath         = Server.MapPath("~/Members/" + note1.SellerID + "/" + note1.ID);
                string displayPicName         = "DisplayPicture" + DateTime.Now.ToString("dd/MM/yyyy") + ".jpg";
                string fulldisplayPicPath     = Path.Combine(displayPicPath, displayPicName);
                string relativeDisplayPicPath = Path.Combine("~/Members/" + note1.SellerID + "/" + note1.ID, displayPicName);
                model.sellerNotesAttachment.FilePath.SaveAs(fulldisplayPicPath);
                fNote.DisplayPicture = relativeDisplayPicPath;

                try
                {
                    context.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            System.Diagnostics.Debug.WriteLine("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                        }
                    }
                }



                string filePath = Server.MapPath("~/Members/" + note1.SellerID + "/" + note1.ID + "/Attachments");
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                string fileName         = "Attachment_" + DateTime.Now.ToString("dd/MM/yyyy") + ".pdf";
                string fullFilePath     = Path.Combine(filePath, fileName);
                string relativeFilePath = Path.Combine("~/Members/" + note1.SellerID + "/" + note1.ID + "/Attachments", fileName);
                model.sellerNotesAttachment.FilePath.SaveAs(fullFilePath);

                var requiredNoteId = context.SellerNotes.Max(x => x.ID);
                Models.SellerNotesAttachment notesAttachment = new Models.SellerNotesAttachment()
                {
                    NoteID       = requiredNoteId,
                    FileName     = fileName,
                    FilePath     = relativeFilePath,
                    CreatedDate  = DateTime.Now,
                    CreatedBy    = note1.SellerID,
                    ModifiedDate = DateTime.Now,
                    ModifiedBy   = note1.SellerID,
                    IsActive     = true
                };

                context.SellerNotesAttachments.Add(notesAttachment);
                try
                {
                    context.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            System.Diagnostics.Debug.WriteLine("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                        }
                    }
                }
            }
            return(View());
        }