コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            addnote f1 = new addnote();

            this.Hide();
            f1.ShowDialog();
        }
コード例 #2
0
 public ActionResult searchNotes(addnote model)
 {
     if (ModelState.IsValid)
     {
         using (NotesMarketPlaceEntities DBobj = new NotesMarketPlaceEntities())
         {
             var list = DBobj.Notes.Where(x => x.NotesCategory == model.NoteCategoryID && x.NotesType == model.NoteTypeID && x.Country == model.CountryID && x.CourseName == model.Course && x.UniversityInformation == model.UniversityInformation);
         }
     }
     return(View());
 }
コード例 #3
0
        public ActionResult addNote(addnote notedetails)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (notedetails.SellType == "Paid" && notedetails.PreviewUpload == null)
                    {
                        NotesMarketPlaceEntities nm = new NotesMarketPlaceEntities();
                        ViewBag.previewmessage = "Note Preview Is Required For Paid Note...";
                        var notecategory = nm.Categories.ToList();
                        var notetype     = nm.Type.ToList();
                        var country      = nm.Country.ToList();
                        ViewBag.notecategoies = new SelectList(notecategory, "CategoryID", "CategoryName");
                        ViewBag.notetypes     = new SelectList(notetype, "TypeID", "TypeName");
                        ViewBag.countries     = new SelectList(country, "CountryID", "CountryName");
                        return(View());
                    }


                    using (NotesMarketPlaceEntities nm = new NotesMarketPlaceEntities())
                    {
                        Notes nd = new Notes();
                        SellerNoteAttachment sna = new SellerNoteAttachment();
                        nd.SellerID              = (int)Session["UserID"];
                        nd.NotesTitle            = notedetails.NoteTitle;
                        nd.NotesCategory         = notedetails.NoteCategoryID;
                        nd.NotesType             = notedetails.NoteTypeID;
                        nd.UniversityInformation = notedetails.UniversityInformation;
                        nd.Country     = notedetails.CountryID;
                        nd.CourseName  = notedetails.Course;
                        nd.CourseCode  = notedetails.CourseCode;
                        nd.Professor   = notedetails.ProfessorName;
                        nd.SellType    = notedetails.SellType;
                        nd.SellPrice   = notedetails.SellPrice;
                        nd.NoOfPages   = notedetails.NumberOfPages;
                        nd.Description = notedetails.NoteDescription;
                        nd.Status      = 4;
                        nd.CreatedDate = DateTime.Now;
                        nd.IsActive    = true;
                        nm.Notes.Add(nd);
                        nm.SaveChanges();

                        string path = Path.Combine(Server.MapPath("~/Member/" + Session["UserID"].ToString()), nd.NoteID.ToString());

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

                        if (notedetails.DisplayPicture != null && notedetails.DisplayPicture.ContentLength > 0)
                        {
                            string fileName  = Path.GetFileNameWithoutExtension(notedetails.DisplayPicture.FileName);
                            string extension = Path.GetExtension(notedetails.DisplayPicture.FileName);
                            fileName = "DP_" + DateTime.Now.ToString("ddMMyyyy") + extension;
                            string finalpath = Path.Combine(path, fileName);
                            notedetails.DisplayPicture.SaveAs(finalpath);

                            nd.NotesDp = Path.Combine(("~/Member/" + Session["UserID"].ToString() + "/" + nd.NoteID.ToString() + "/"), fileName);
                            nm.SaveChanges();
                        }
                        if (notedetails.PreviewUpload != null && notedetails.PreviewUpload.ContentLength > 0)
                        {
                            string fileName  = Path.GetFileNameWithoutExtension(notedetails.PreviewUpload.FileName);
                            string extension = Path.GetExtension(notedetails.PreviewUpload.FileName);
                            fileName = "PREVIEW_" + DateTime.Now.ToString("ddMMyyyy") + extension;
                            string finalpath = Path.Combine(path, fileName);
                            notedetails.PreviewUpload.SaveAs(finalpath);

                            nd.PreviewUpload = Path.Combine(("~/Member/" + Session["UserID"].ToString() + "/" + nd.NoteID.ToString() + "/"), fileName);
                            nm.SaveChanges();
                        }

                        string attachmentpath = Path.Combine(Server.MapPath("~/Member/" + Session["UserID"].ToString() + "/" + nd.NoteID.ToString()), "attachment");

                        if (!Directory.Exists(attachmentpath))
                        {
                            Directory.CreateDirectory(attachmentpath);
                        }
                        if (notedetails.NotesAttachment != null && notedetails.NotesAttachment[0].ContentLength > 0)
                        {
                            var count    = 1;
                            var FilePath = "";
                            var FileName = "";
                            foreach (var file in notedetails.NotesAttachment)
                            {
                                string fileName  = Path.GetFileNameWithoutExtension(file.FileName);
                                string extension = Path.GetExtension(file.FileName);
                                fileName = "Attachment_" + count + "_" + DateTime.Now.ToString("ddMMyyyy") + extension;
                                string finalpath = Path.Combine(attachmentpath, fileName);
                                file.SaveAs(finalpath);
                                FileName += fileName + ";";
                                FilePath += Path.Combine(("~/Member/" + Session["UserID"].ToString() + "/" + nd.NoteID.ToString() + "/"), fileName) + ";";
                                count++;
                            }
                            sna.FileName = FileName;
                            sna.FilePath = FilePath;

                            sna.NoteID      = nd.NoteID;
                            sna.IsActive    = true;
                            sna.CreatedDate = DateTime.Now;
                            sna.CreatedBy   = (int)Session["UserID"];
                            nm.SaveChanges();
                        }
                        nm.SellerNoteAttachment.Add(sna);
                        nm.SaveChanges();
                    }
                }

                ModelState.Clear();
                return(RedirectToAction("addNote", "User"));
            }
            catch (DbEntityValidationException e)
            {
                Console.WriteLine(e);
            }



            return(View());
        }