public ActionResult Editnote(int Id, UserSellernotes editnote, string SAVE) { SellerNote sellrnote = dbobj.SellerNotes.Find(Id); sellrnote.Title = editnote.Title; sellrnote.Category = editnote.Category; sellrnote.Description = editnote.Description; sellrnote.IsPaid = editnote.IsPaid; sellrnote.NoteType = editnote.NoteType; sellrnote.NumberofPages = editnote.NumberofPages; sellrnote.UniversityName = editnote.UniversityName; sellrnote.Country = editnote.Country; sellrnote.Course = editnote.Course; sellrnote.CourseCode = editnote.CourseCode; sellrnote.Professor = editnote.Professor; sellrnote.SellingPrice = editnote.SellingPrice; sellrnote.ModifiedDate = DateTime.Now; sellrnote.IsActive = true; if (SAVE == "save") { sellrnote.Status = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status" && x.value.ToLower() == "draft").Select(x => x.Id).FirstOrDefault(); } else { sellrnote.Status = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status" && x.value.ToLower() == "submitted for review").Select(x => x.Id).FirstOrDefault(); SystemConfiguration system = dbobj.SystemConfigurations.Where(x => x.Key == "SupportEmail").FirstOrDefault(); SystemConfiguration system1 = dbobj.SystemConfigurations.Where(x => x.Key == "Password").FirstOrDefault(); SystemConfiguration system2 = dbobj.SystemConfigurations.Where(x => x.Key == "EmailAddress").FirstOrDefault(); SendEmailToAdmin(system.Value, system1.Value, system2.Value, Id); } dbobj.Entry(sellrnote).State = EntityState.Modified; dbobj.SaveChanges(); if (sellrnote == null) { return(HttpNotFound()); } ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true); ViewBag.NoteType = dbobj.NoteTypes.Where(x => x.IsActive == true); ViewBag.Country = dbobj.Countries.Where(x => x.isActive == true); return(RedirectToAction("Dashboard", "Notes")); return(View(sellrnote)); }
public ActionResult Editnote(int?Id) { if (Id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SellerNote sellrnote = dbobj.SellerNotes.Find(Id); SellerNotesAttachement objsellernoteattachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == Id).FirstOrDefault(); UserSellernotes editnote = new UserSellernotes { ID = sellrnote.Id, Title = sellrnote.Title, Category = sellrnote.Category, Description = sellrnote.Description, IsPaid = sellrnote.IsPaid, NoteType = sellrnote.NoteType, NumberofPages = sellrnote.NumberofPages, UniversityName = sellrnote.UniversityName, Country = sellrnote.Country, Course = sellrnote.Course, CourseCode = sellrnote.CourseCode, Professor = sellrnote.Professor, SellingPrice = sellrnote.SellingPrice, CreatedDate = sellrnote.CreatedDate }; if (sellrnote == null) { return(HttpNotFound()); } ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true); ViewBag.NoteType = dbobj.NoteTypes.Where(x => x.IsActive == true); ViewBag.Country = dbobj.Countries.Where(x => x.isActive == true); return(View(editnote)); }
public ActionResult addnotes(UserSellernotes note) { if (ModelState.IsValid) { var Emailid = User.Identity.Name.ToString(); User user = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault(); Referencedata rf = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status").FirstOrDefault(); SellerNote objsellernote = new SellerNote { SellerID = user.ID, Status = rf.Id, Title = note.Title, Category = note.Category, NoteType = note.NoteType, Professor = note.Professor, Description = note.Description, IsPaid = note.IsPaid, NumberofPages = note.NumberofPages, UniversityName = note.UniversityName, Country = note.Country, Course = note.Course, CourseCode = note.CourseCode, SellingPrice = note.SellingPrice, CreatedDate = DateTime.Now, IsActive = true }; dbobj.SellerNotes.Add(objsellernote); dbobj.SaveChanges(); var noteID = objsellernote.Id; //display picture //generate path to store image string storepath = Path.Combine(Server.MapPath("/UploadFiles/" + user.ID), noteID.ToString()); //check for directory, if not exist ,then create it if (!Directory.Exists(storepath)) { Directory.CreateDirectory(storepath); } if (note.DisplayPicture != null && note.DisplayPicture.ContentLength > 0) { string _FileName = Path.GetFileNameWithoutExtension(note.DisplayPicture.FileName); string extension = Path.GetExtension(note.DisplayPicture.FileName); _FileName = "DP_" + DateTime.Now.ToString("yymmssfff") + extension; string finalpath = Path.Combine(storepath, _FileName); note.DisplayPicture.SaveAs(finalpath); objsellernote.DisplayPicture = Path.Combine(("/UploadFiles/" + user.ID + "/" + noteID + "/"), _FileName); dbobj.SaveChanges(); } else { objsellernote.DisplayPicture = "/System Configuration/DefaultImage/4.jpg"; dbobj.SaveChanges(); } //upload notes string storeuploadpath = Path.Combine(storepath, "Attachments"); //check for directory, if not exist ,then create it if (!Directory.Exists(storeuploadpath)) { Directory.CreateDirectory(storeuploadpath); } SellerNotesAttachement objsellernoteattachment = new SellerNotesAttachement { NoteID = noteID, IsActive = true, CreatedBy = user.ID, Createddate = DateTime.Now }; // int count = 1; var UploadnoteFilePath = ""; var UploadnoteFileName = ""; foreach (var File in note.UploadNotes) { string _FileName = Path.GetFileNameWithoutExtension(File.FileName); string extension = Path.GetExtension(File.FileName); _FileName = "Attachment" + count + "_" + DateTime.Now.ToString("ddmyyyy") + extension; string finalpath = Path.Combine(storeuploadpath, _FileName); File.SaveAs(finalpath); UploadnoteFileName += _FileName + ";"; UploadnoteFilePath += Path.Combine(("/UploadFiles/" + user.ID + "/" + noteID + "/Attachment/"), _FileName); count++; } objsellernoteattachment.FileName = UploadnoteFileName; objsellernoteattachment.FilePath = UploadnoteFilePath; dbobj.SellerNotesAttachements.Add(objsellernoteattachment); dbobj.SaveChanges(); //notes preview if (note.IsPaid == true) { if (note.NotesPreview == null) { ViewBag.ErrorMessage = "plz upload preview"; ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true); ViewBag.NoteType = dbobj.NoteTypes.Where(x => x.IsActive == true); ViewBag.Country = dbobj.Countries.Where(x => x.isActive == true); return(View(note)); } } if (note.NotesPreview != null && note.NotesPreview.ContentLength > 0) { string _FileName = Path.GetFileNameWithoutExtension(note.NotesPreview.FileName); string extension = Path.GetExtension(note.NotesPreview.FileName); _FileName = "Preview_" + DateTime.Now.ToString("yymmssfff") + extension; string finalpath = Path.Combine(storepath, _FileName); note.NotesPreview.SaveAs(finalpath); objsellernote.NotesPreview = Path.Combine(("/UploadFiles/" + user.ID + "/" + noteID + "/"), _FileName); dbobj.SaveChanges(); } return(RedirectToAction("Dashboard", "Notes")); } ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true); ViewBag.NoteType = dbobj.NoteTypes.Where(x => x.IsActive == true); ViewBag.Country = dbobj.Countries.Where(x => x.isActive == true); return(View(note)); }