public void MaptoModel(tblSellerNote note, tblSellerNotesAttachement attachment)
 {
     note.Title          = Title;
     note.Category       = Category;
     note.DisplayPicture = DisplayPicture;
     note.NoteType       = NoteType;
     note.NumberofPages  = NumberofPages;
     note.Description    = Description;
     note.UniversityName = UniversityName;
     note.Country        = Country;
     note.Course         = Course;
     note.CourseCode     = CourseCode;
     note.Professor      = Professor;
     note.SellingPrice   = SellingPrice;
     note.NotesPreview   = NotePreview;
     attachment.FileName = UploadNotes;
 }
Ejemplo n.º 2
0
        public ActionResult Add_Notes(tblSellerNote model)
        {
            NotesMarketPlaceEntities entities = new NotesMarketPlaceEntities();
            var        NoteCategory           = entities.tblNoteCategories.ToList();
            SelectList list = new SelectList(NoteCategory, "ID", "Name");

            ViewBag.NoteCategory = list;


            var        NoteType     = entities.tblNoteTypes.ToList();
            SelectList NoteTypelist = new SelectList(NoteType, "ID", "Name");

            ViewBag.NoteType = NoteTypelist;


            var        CountryName = entities.tblCountries.ToList();
            SelectList CountryList = new SelectList(CountryName, "ID", "Name");

            ViewBag.Country = CountryList;


            string name                 = User.Identity.Name;
            int    access               = (from user in dbobject.tblUsers where user.EmailID == name select user.ID).Single();
            string book_title           = model.Title;
            string notename_fullpath    = null;
            string picname_fullpath     = null;
            string previewname_fullpath = null;

            tblSellerNote obj = new tblSellerNote();

            int lastid = (from row in dbobject.tblSellerNotes orderby row.ID descending select row.ID).FirstOrDefault();

            lastid += 1;
            string defaultpath = Server.MapPath(string.Format("~/Content/Files/{0}", lastid));

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

            if (model.uploadNote != null)
            {
                string notename = Path.GetFileName(model.uploadNote.FileName);
                notename_fullpath = Path.Combine(defaultpath, notename);
                model.uploadNote.SaveAs(notename_fullpath);
            }
            else
            {
                ViewBag.Message = "Please upload note";
                return(View());
            }

            if (model.displayPic != null)
            {
                string picname = Path.GetFileName(model.displayPic.FileName);
                picname_fullpath = Path.Combine(defaultpath, picname);
                model.displayPic.SaveAs(picname_fullpath);
                obj.DisplayPicture = picname_fullpath;
            }

            if (model.notePreview != null)
            {
                string previewname = Path.GetFileName(model.notePreview.FileName);
                previewname_fullpath = Path.Combine(defaultpath, previewname);
                model.notePreview.SaveAs(previewname_fullpath);
                obj.NotesPreview = previewname_fullpath;
            }

            obj.SellerID       = access;
            obj.Title          = model.Title;
            obj.Category       = model.Category;
            obj.NoteType       = model.NoteType;
            obj.NumberofPages  = model.NumberofPages;
            obj.Description    = model.Description;
            obj.UniversityName = model.UniversityName;
            obj.Country        = model.Country;
            obj.Course         = model.Course;
            obj.CourseCode     = model.CourseCode;
            obj.Professor      = model.Professor;
            obj.Status         = 7;
            obj.CreatedDate    = DateTime.Now;
            obj.CreatedBy      = access;
            obj.IsActive       = true;

            obj.IsPaid = model.IsPaid;
            if (obj.IsPaid)
            {
                obj.SellingPrice = model.SellingPrice;
            }
            else
            {
                obj.SellingPrice = 0;
            }

            dbobject.tblSellerNotes.Add(obj);
            dbobject.SaveChanges();
            //try
            //{
            //    dbobject.SaveChanges();
            //}
            //catch (DbEntityValidationException e)
            //{
            //    foreach (var eve in e.EntityValidationErrors)
            //    {
            //        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
            //            eve.Entry.Entity.GetType().Name, eve.Entry.State);
            //        foreach (var ve in eve.ValidationErrors)
            //        {
            //            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
            //                ve.PropertyName, ve.ErrorMessage);
            //        }
            //    }
            //}


            int book_id = (from record in dbobject.tblSellerNotes where record.SellerID == access && record.Title == book_title orderby record.ID descending select record.ID).First();

            tblSellerNotesAttachement sellerattachment = new tblSellerNotesAttachement();

            sellerattachment.NoteID      = book_id;
            sellerattachment.FilePath    = notename_fullpath;
            sellerattachment.FileName    = book_title;
            sellerattachment.CreatedBy   = access;
            sellerattachment.CreatedDate = DateTime.Now;
            sellerattachment.IsActive    = true;
            dbobject.tblSellerNotesAttachements.Add(sellerattachment);
            dbobject.SaveChanges();
            ModelState.Clear();

            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult addnote(tblSellerNote model)
        {
            NotesMarketPlaceEntities entities = new NotesMarketPlaceEntities();
            var        NoteCategory           = entities.tblNoteCategories.ToList();
            SelectList list = new SelectList(NoteCategory, "ID", "Name");

            ViewBag.NoteCategory = list;


            var        NoteType     = entities.tblNoteTypes.ToList();
            SelectList NoteTypelist = new SelectList(NoteType, "ID", "Name");

            ViewBag.NoteType = NoteTypelist;


            var        CountryName = entities.tblCountries.ToList();
            SelectList CountryList = new SelectList(CountryName, "ID", "Name");

            ViewBag.Country = CountryList;



            string name                 = User.Identity.Name;
            int    u                    = (from user in dbobj.tblUsers where user.EmailID == name select user.ID).Single();
            string book_title           = model.Title;
            string notename_fullpath    = null;
            string picname_fullpath     = null;
            string previewname_fullpath = null;

            tblSellerNote obj = new tblSellerNote();



            if (model.uploadNote != null)
            {
                string notepath = Server.MapPath("~/App_Data/Files");
                string notename = Path.GetFileName(model.uploadNote.FileName);
                notename_fullpath = Path.Combine(notepath, notename);
                model.uploadNote.SaveAs(notename_fullpath);
            }
            else
            {
                ViewBag.Message = "Please Upload You File";
                return(View());
            }

            if (model.displayPic != null)
            {
                string picpath = Server.MapPath("~/App_Data/Files");
                string picname = Path.GetFileName(model.displayPic.FileName);
                picname_fullpath = Path.Combine(picpath, picname);
                model.displayPic.SaveAs(picname_fullpath);
                obj.DisplayPicture = picname_fullpath;
            }
            if (model.notePreview != null)
            {
                string previewpath = Server.MapPath("~/App_Data/Files");
                string previewname = Path.GetFileName(model.notePreview.FileName);
                previewname_fullpath = Path.Combine(previewpath, previewname);
                model.notePreview.SaveAs(previewname_fullpath);
                obj.NotesPreview = previewname_fullpath;
            }



            try
            {
                obj.SellerID       = u;
                obj.Title          = model.Title;
                obj.Category       = model.Category;
                obj.NoteType       = model.NoteType;
                obj.NumberofPages  = model.NumberofPages;
                obj.Description    = model.Description;
                obj.UniversityName = model.UniversityName;
                obj.Country        = model.Country;
                obj.Course         = model.Course;
                obj.CourseCode     = model.CourseCode;
                obj.Professor      = model.Professor;
                obj.Status         = 7;

                obj.IsActive     = true;
                obj.SellingPrice = model.SellingPrice;
                obj.IsPaid       = model.IsPaid;

                dbobj.tblSellerNotes.Add(obj);
                dbobj.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
            }


            int book_id = (from record in dbobj.tblSellerNotes where record.SellerID == u && record.Title == book_title select record.ID).First();

            try
            {
                tblSellerNotesAttachement sellerattachment = new tblSellerNotesAttachement();
                sellerattachment.NoteID      = book_id;
                sellerattachment.FilePath    = notename_fullpath;
                sellerattachment.FileName    = book_title;
                sellerattachment.CreatedBy   = u;
                sellerattachment.CreatedDate = DateTime.Now;
                sellerattachment.IsActive    = true;
                dbobj.tblSellerNotesAttachements.Add(sellerattachment);
                dbobj.SaveChanges();
            }
            catch
            {
            }
            return(View());
        }