public ActionResult contactUs(ContactUs model) { try { if (ModelState.IsValid) { using (NotesMarketPlaceEntities DBobj = new NotesMarketPlaceEntities()) { ContactUs u = new ContactUs(); u.FullName = model.FullName; u.EmailAddress = model.EmailAddress; u.Subject = model.Subject; u.Comments = model.Comments; u.CreatedDate = DateTime.Now; u.IsActive = true; DBobj.ContactUs.Add(u); DBobj.SaveChanges(); if (u.ContactID > 0) { ModelState.Clear(); ContactUsEmail.ContactUs(model.Subject, model.FullName, model.Comments); return(View()); } } } return(View()); } catch (Exception e) { return(View()); } }
public static bool RejectNote(int NoteID, int AdminID, string Remarks) { using (NotesMarketPlaceEntities context = new NotesMarketPlaceEntities()) { var note = context.Notes.FirstOrDefault(n => n.NoteID == NoteID && (n.NoteStatus == 1 || n.NoteStatus == 2)); if (note == null) { return(false); } else { note.NoteStatus = 4; note.ModifiedDate = System.DateTime.Now; note.ModifiedBy = AdminID; note.ActionBy = AdminID; note.AdminRemarks = Remarks; } try { context.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }
//buyer allow then download process... public ActionResult downloadBook(int id) { NotesMarketPlaceEntities a = new NotesMarketPlaceEntities(); var user_id = dbobject.tblUsers.Where(m => m.EmailID.Equals(User.Identity.Name)).FirstOrDefault(); var download = dbobject.tblDownloads.Where(m => m.ID == id && m.Downloader.Equals(user_id.ID)).FirstOrDefault(); if (download == null || download.IsSellerHasAllowedDownload != true) { return(HttpNotFound()); } else if (download != null) { string path = download.AttachmentPath; string filename = download.NoteTitle; filename += ".pdf"; download.IsAttachmentDownloaded = true; download.AttachmentDownloadedDate = DateTime.Now; dbobject.SaveChanges(); byte[] fileBytes = System.IO.File.ReadAllBytes(path); return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, filename)); } return(HttpNotFound()); }
public ActionResult Buyer_Allowed(int id) { NotesMarketPlaceEntities a = new NotesMarketPlaceEntities(); var obj = a.tblDownloads.Where(m => m.ID.Equals(id)).FirstOrDefault(); int buyer_id = obj.Downloader; int seller_id = obj.Seller; var buyer = a.tblUsers.Where(m => m.ID.Equals(buyer_id)).FirstOrDefault(); var seller = a.tblUsers.Where(m => m.ID.Equals(seller_id)).FirstOrDefault(); if (obj != null) { // int id = admin_id.ID; obj.IsSellerHasAllowedDownload = true; string buyer_email = buyer.EmailID; string buyer_name = buyer.FirstName; buyer_name += " " + buyer.LastName; string seller_name = seller.FirstName; seller_name += " " + seller.LastName; string subject = seller_name + " Allows you to download a note"; ForgotPass mailer = new ForgotPass(); string body = "Hello " + buyer_name + ",<br/><br/>We would like to inform you that," + seller_name + " Allows you to download a note." + "Please login and see My Download tabs to download particular note." + "<br/><br/>Regards,<br/>Notes Marketplace"; mailer.sendMail(subject, body, buyer_email); a.SaveChanges(); } return(RedirectToAction("Buyer_requests", "Client")); }
/// <summary> /// Approves Note i.e changes status to 3: published and adds admin's id and remarks as Ok /// </summary> /// <param name="NoteID">Note To Be Approved</param> /// <param name="AdminID">UserID of Admin that approved the note.</param> /// <returns> int: meaning /// 1: Successful /// 0: Unsuccessful /// -1: Already inreview /// </returns> public static int MakeNoteInReview(int NoteID, int AdminID) { using (NotesMarketPlaceEntities context = new NotesMarketPlaceEntities()) { var note = context.Notes.FirstOrDefault(n => n.NoteID == NoteID && (n.NoteStatus == 1 || n.NoteStatus == 2)); if (note == null) { return(0); } else if (note.NoteStatus == 2) { return(-1); } else { note.NoteStatus = 2; note.ModifiedDate = System.DateTime.Now; note.ModifiedBy = AdminID; note.ActionBy = AdminID; } try { context.SaveChanges(); return(1); } catch (Exception e) { return(0); } } }
// initialize user information protected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); if (requestContext.HttpContext.User.Identity.IsAuthenticated) { using (var _Context = new NotesMarketPlaceEntities()) { // get current user profile image var currentUserImg = (from details in _Context.tblUserProfiles join users in _Context.tblUsers on details.UserID equals users.ID where users.EmailID == requestContext.HttpContext.User.Identity.Name select details.ProfilePicture).FirstOrDefault(); if (currentUserImg == null) { // get deafult image var defaultImg = _Context.tblSystemConfigurations.FirstOrDefault(model => model.Key == "DefaultMemberDisplayPicture").Values; ViewBag.UserProfile = defaultImg; } else { ViewBag.UserProfile = currentUserImg; } } } }
/// <summary> /// Delete review from Database /// </summary> /// <param name="ReviewID">ReviewID of review to be deleted</param> /// <returns>Return NoteID of Review Deleted or 0 if fails to delete review</returns> public static bool DeleteReview(int ReviewID) { using (var context = new NotesMarketPlaceEntities()) { var Review = context.NotesReviews.FirstOrDefault(nr => nr.ReviewID == ReviewID); if (Review == null) { return(false); } int NoteID = Review.NoteID; context.NotesReviews.Remove(Review); try { context.SaveChanges(); } catch (Exception e) { Debug.WriteLine(e); return(false); } return(true); } }
public static string GetRole(int UID) { using (NotesMarketPlaceEntities context = new NotesMarketPlaceEntities()) { return(context.Users.FirstOrDefault(u => u.UserID == UID).UserRole.RoleName); } }
public static string ForgotPassword(string emailAddress) { using (NotesMarketPlaceEntities context = new NotesMarketPlaceEntities()) { User u = context.Users.FirstOrDefault(user => user.Email == emailAddress && user.IsActive); if (u == null) { return(string.Empty); } string elements = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*+=^"; Random PassGenerator = new Random(); StringBuilder NewPass = new StringBuilder(); for (int i = 0; i < 10; i++) { NewPass.Append(elements[PassGenerator.Next(0, elements.Length)]); } string pass = NewPass.ToString(); u.Passwd = pass; u.ModifiedDate = System.DateTime.Now; u.ModifiedBy = 1; context.SaveChanges(); return(pass); } }
public static List <DashboardModel.PublishedNotesClass> GetPublishedNotes(int UserID) { using (var context = new NotesMarketPlaceEntities()) { var NotesInDB = context.Notes.Where(n => n.SellerID == UserID && (n.NoteStatus == 3) && n.IsActive); if (NotesInDB.Count() == 0) { return(null); } var PublishedNotes = new List <DashboardModel.PublishedNotesClass>(); foreach (var Note in NotesInDB) { PublishedNotes.Add( new DashboardModel.PublishedNotesClass() { NoteID = Note.NoteID, NoteTitle = Note.Title, NoteCategory = context.NoteCategories.FirstOrDefault(nc => nc.CategoryID == Note.Category).CategoryName, AddedDate = Note.ModifiedDate, Price = Note.Price ?? 0, SellType = Note.IsPaid ? "Paid" : "Free" }); } return(PublishedNotes); } }
/// <summary> /// Get all notes in review for admin /// </summary> /// <returns>Return List of AdminNotesInReview's Inner class NotesInReview</returns> public static List <AdminNotesInReviewModel.NoteInReview> GetNotesInReviews() { using (var context = new NotesMarketPlaceEntities()) { var NotesInDB = context.Notes.Where(n => n.NoteStatus == 1 || n.NoteStatus == 2).ToList(); List <AdminNotesInReviewModel.NoteInReview> Notes = new List <AdminNotesInReviewModel.NoteInReview>(); foreach (var note in NotesInDB) { User Seller = context.Users.FirstOrDefault(u => u.UserID == note.SellerID); Notes.Add(new AdminNotesInReviewModel.NoteInReview() { NoteID = note.NoteID, NoteTitle = note.Title, NoteCategory = note.NoteCategory.CategoryName, Seller = Seller.FirstName + " " + Seller.LastName, SellerID = Seller.UserID, DateAdded = note.ModifiedDate, status = note.NoteStatus == 1 ? "Submitted For Review" : "In Review" }); } return(Notes); } }
public static int AddUser(SignUp NewUser) { using (var context = new NotesMarketPlaceEntities()) { if (context.Users.Any(m => m.Email == NewUser.Email && m.IsActive)) { return(0); } User u = new User() { FirstName = NewUser.FirstName, LastName = NewUser.LastName, Email = NewUser.Email, IsEmailVerified = false, RoleID = (int)NewUser.RoleID, ModifiedDate = DateTime.Now, Passwd = NewUser.Password, IsActive = true, GUID = NewUser.GUID, CreatedBy = 1, ModifiedBy = 1, CreatedDate = System.DateTime.Now, }; context.Users.Add(u); context.SaveChanges(); return(u.UserID); } }
/// <summary> /// loads Published notes having status 3 in a list of <code>AdminDashboardModel.PublishedNote</code> and returns it /// </summary> /// <returns>List of type <code>AdminDashboardModel.PublishedNote</code></returns> public static List <AdminDashboardModel.PublishedNote> GetPublishedNotes() { using (var context = new NotesMarketPlaceEntities()) { var PublishedNotesInDB = context.Notes.Where(n => n.NoteStatus == 3).ToList(); List <AdminDashboardModel.PublishedNote> PublishedNotes = new List <AdminDashboardModel.PublishedNote>(); foreach (var note in PublishedNotesInDB) { User Seller = context.Users.FirstOrDefault(u => u.UserID == note.SellerID); User Admin = context.Users.FirstOrDefault(u => u.UserID == note.ActionBy); PublishedNotes.Add(new AdminDashboardModel.PublishedNote() { NoteID = note.NoteID, NoteTitle = note.Title, Category = note.NoteCategory.CategoryName, AttachmentSize = context.NotesAttachments.FirstOrDefault(na => na.NoteID == note.NoteID).AttachmentSize, SellType = note.IsPaid ? "Paid" : "Free", Price = note.Price ?? 0, Publisher = Seller.FirstName + " " + Seller.LastName, PublishedDate = note.PublishedDate, NoOfDownloads = context.Downloads.Where(dwn => dwn.NoteID == note.NoteID && dwn.IsAllowed && dwn.User.RoleID > 2).Count(), ApprovedBy = Admin.FirstName + " " + Admin.LastName, PublisherID = Seller.UserID }); } return(PublishedNotes); } }
/// <summary> /// Get Counts of notes in review /// </summary> /// <returns>Int count of notes in reviews</returns> public static int GetCountNotesInReview() { using (var context = new NotesMarketPlaceEntities()) { return(context.Notes.Where(n => n.NoteStatus == 2 || n.NoteStatus == 1).Count()); } }
/* Get Report variables if already reported and check if allowed to report note, it retuns rate model with note id = -1 * if not allowed and return reportmodel with note title if report not exists * */ public static ReportNoteModel GetNoteReport(int NoteID, int UserID) { using (var context = new NotesMarketPlaceEntities()) { var IsAllowedToRate = context.Downloads.Any(dwn => dwn.NoteID == NoteID && dwn.BuyerID == UserID && dwn.IsAllowed && dwn.IsDownloaded); if (!IsAllowedToRate) { return(new ReportNoteModel() { NoteID = -1 }); //Not allowed return RatingModel with note id = -1 } else { var Report = context.NotesReports.FirstOrDefault(r => r.NoteID == NoteID && r.BuyerID == UserID); if (Report == null) { return(new ReportNoteModel() { NoteTitle = context.Notes.FirstOrDefault(n => n.NoteID == NoteID).Title }); //report not found } else { return(new ReportNoteModel() { NoteID = Report.NoteID, Remarks = Report.Remarks, NoteTitle = context.Notes.FirstOrDefault(n => n.NoteID == NoteID).Title }); } } } }
/* Get Rating variables if already rated and check if allowed to rate note, it retuns rate model with note id = -1 * if not allowed and return null if reviews not exists * */ public static RatingModel GetNoteRating(int NoteID, int UserID) { using (var context = new NotesMarketPlaceEntities()) { var IsAllowedToRate = context.Downloads.Any(dwn => dwn.NoteID == NoteID && dwn.BuyerID == UserID && dwn.IsAllowed && dwn.IsDownloaded); if (!IsAllowedToRate) { return(new RatingModel() { NoteID = -1 }); //Not allowed return RatingModel with note id = -1 } else { var Rating = context.NotesReviews.FirstOrDefault(r => r.NoteID == NoteID && r.BuyerID == UserID); if (Rating == null) { return(null); //rating not found } else { return(new RatingModel() { NoteID = Rating.NoteID, Stars = (int)Rating.Rating, Comment = Rating.Comment }); } } } }
public static RejectedNotes GetRejectedNotes(int UserID) { using (var context = new NotesMarketPlaceEntities()) { var RejectedNotesInDB = context.Notes.Where(n => n.SellerID == UserID && n.NoteStatus == 4); if (RejectedNotesInDB.Count() == 0) { return(new RejectedNotes()); } var rejectedNotes = new RejectedNotes(); foreach (var note in RejectedNotesInDB) { rejectedNotes.RejectedNotesList.Add(new RejectedNotes.RejectedNote() { NoteID = note.NoteID, NoteTitle = note.Title, Remarks = note.AdminRemarks ?? "N/A", NoteCategory = note.NoteCategory.CategoryName }); } return(rejectedNotes); } }
public static int VerifyEmail(int UID, string strGuid) { using (NotesMarketPlaceEntities context = new NotesMarketPlaceEntities()) { User u = context.Users.FirstOrDefault(us => us.UserID == UID && us.GUID == strGuid && us.IsActive); // return 1 if successful verification if (u != null) { //If already Verified send -1 if (u.IsEmailVerified) { return(-1); } u.GUID = null; u.IsEmailVerified = true; u.ModifiedDate = System.DateTime.Now; u.ModifiedBy = u.UserID; context.SaveChanges(); return(1); } //return 0 if uid and guid does not match else { return(0); } } }
public ActionResult ChangePassword(ChangePassword pwd) { if (!ModelState.IsValid) { return(View()); } using (var _Context = new NotesMarketPlaceEntities()) { // get current user var currentUser = _Context.tblUsers.FirstOrDefault(model => model.EmailID == User.Identity.Name); // check old password if (!currentUser.Password.Equals(pwd.OldPassword)) { ModelState.AddModelError("Error", "Old password is wrong"); return(View()); } else { // update password currentUser.Password = pwd.ConfirmPassword; currentUser.ModifiedDate = DateTime.Now; _Context.SaveChanges(); FormsAuthentication.SignOut(); return(RedirectToAction("Login", "Account")); } } }
/// <summary> /// Get Counts of downloads of last <code>BeforeDays</code> Days. /// </summary> /// <param name="BeforeDays">No of past days to be considered</param> /// <returns>Int count of downloads</returns> public static int CountNewDownloads(int BeforeDays = 7) { using (var context = new NotesMarketPlaceEntities()) { System.DateTime Criteria = System.DateTime.Now.AddDays(-1 * BeforeDays); return(context.Downloads.Where(dwn => dwn.ModifiedDate > Criteria && dwn.IsAllowed).Count()); } }
/// <summary> /// Get Counts of new users of last <code>BeforeDays</code> Days. /// </summary> /// <param name="BeforeDays">No of past days to be considered</param> /// <returns>Int count of new users</returns> public static int CountNewUsers(int BeforeDays = 7) { using (var context = new NotesMarketPlaceEntities()) { DateTime Criteria = System.DateTime.Now.AddDays(BeforeDays * -1); return(context.Users.Where(u => u.CreatedDate >= Criteria).Count()); } }
public ActionResult UserProfile(UserProfileModel user) { if (!ModelState.IsValid) { return(View()); } using (var _Context = new NotesMarketPlaceEntities()) { // current userID int currentUser = _Context.tblUsers.FirstOrDefault(model => model.EmailID == User.Identity.Name).ID; // user details var userdetails = _Context.tblUserProfiles.FirstOrDefault(model => model.UserID == currentUser); var defaultImg = _Context.tblSystemConfigurations.Single(x => x.Key == "DefaultMemberDisplayPicture").Values; // check user available or not if (userdetails != null && user != null) { // update details var userUpdate = _Context.tblUsers.FirstOrDefault(model => model.ID == currentUser); var update = _Context.tblUserProfiles.FirstOrDefault(model => model.UserID == currentUser); user.MaptoModel(userUpdate, update); // "../Members/"+ currentUser+ "/"+user.ProfilePicture aa lakhi nakj update.ProfilePicture = "../Members/" + currentUser + "/" + user.ProfilePicture; userUpdate.ModifiedDate = DateTime.Now; update.ModifiedDate = DateTime.Now; _Context.SaveChanges(); return(RedirectToAction("UserProfile")); } else { // add new details var add = _Context.tblUserProfiles; add.Add(new tblUserProfile { UserID = currentUser, DOB = user.DOB, Gender = user.Gender, PhoneNumber_CountryCode = user.PhoneNumber_CountryCode, PhoneNumber = user.PhoneNumber, ProfilePicture = user.ProfilePicture == null ? default : "../Members/" + currentUser + "/" + user.ProfilePicture, AddressLine1 = user.AddressLine1, AddressLine2 = user.AddressLine2, City = user.City, State = user.State, ZipCode = user.ZipCode, Country = user.Country, University = user.University, College = user.College, CreatedDate = DateTime.Now });
public ActionResult addAdmin() { NotesMarketPlaceEntities entities = new NotesMarketPlaceEntities(); var CountryCode = entities.tblCountries.ToList(); SelectList list = new SelectList(CountryCode, "CountryCode", "CountryCode"); ViewBag.CountryCode = list; return(View()); }
public override string[] GetRolesForUser(string username) { NotesMarketPlaceEntities db = new NotesMarketPlaceEntities(); var userRoles = (from user in db.Users join role in db.UserRoles on user.RoleID equals role.ID where user.Email == username select role.Name).ToArray(); return(userRoles); }
public static UserProfileModel GetUserData(int UID) { using (NotesMarketPlaceEntities context = new NotesMarketPlaceEntities()) { User user = context.Users.FirstOrDefault(u => u.UserID == UID); if (user == null) { return(null); } //get user sign data into model UserModel userModel = new UserModel() { Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, RoleID = user.RoleID, IsEmailVerified = user.IsEmailVerified }; //If not found profile data then send user signup data only and redirect user on user profile page to enter data if (!context.UserProfiles.Any(u => u.UserID == UID)) { return new UserProfileModel() { User = userModel } } ; //if found user profile realted to this user return all data with signup data in user variable UserProfile up = context.UserProfiles.FirstOrDefault(u => u.UserID == UID); UserProfileModel upModel = new UserProfileModel() { UserID = up.UserID, DOB = up.DOB, Gender = up.Gender != null?context.ReferenceDatas.FirstOrDefault(r => r.DataID == up.Gender).DataKey : null, SecondaryEmailAddress = up.SecondaryEmailAddress, CountryCode = up.CountryCode, PhoneNo = up.PhoneNo, ProfilePicture = up.ProfilePicture, AddressLine1 = up.AddressLine1, AddressLine2 = up.AddressLine2, City = up.City, State = up.State, ZipCode = up.ZipCode, Country = up.Country1.CountryName, University = up.University, College = up.College, User = userModel }; return(upModel); } }
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()); }
//GET: Notedetails public ActionResult noteDetails() { int id = 1; using (NotesMarketPlaceEntities DBobj = new NotesMarketPlaceEntities()) { var note = DBobj.Notes.Where(x => x.NoteID == id).ToList(); var category = DBobj.Categories.ToList(); var country = DBobj.Country.ToList(); var notedetail = (from n in note join c in category on n.NotesCategory equals c.CategoryID into table1 from c in table1.ToList() join cr in country on n.Country equals cr.CountryID into table2 from cr in table2.ToList() select new nd { note = n, Category = c, contryname = cr }).ToList(); ViewBag.notedetailbag = notedetail; var reviews = DBobj.UsersReviews.ToList(); var users = DBobj.Users.ToList(); var reviewdetail = (from nr in reviews join n in note on nr.NoteID equals n.NoteID into table3 from n in table3.ToList() join us in users on nr.ReviewedBy equals us.UserID into table4 from us in table4.ToList() select new reviewtable { note = n, notereview = nr, usr = us }).ToList(); ViewBag.reviewdetailbag = reviewdetail; ViewBag.reviewcount = reviewdetail.Count(); var spam = DBobj.SpamReports.ToList(); var spamtotal = (from sp in spam join n in note on sp.NoteID equals id into table5 from n in table5.ToList() select new spamtable { note = n, spamrpt = sp }).ToList(); ViewBag.spamtotalcount = spamtotal.Count(); } return(View()); }
public ActionResult signUp(signUp model) { try { if (ModelState.IsValid) { using (NotesMarketPlaceEntities DBobj = new NotesMarketPlaceEntities()) { Users u = new Users(); u.RoleID = 1003; u.FirstName = model.FirstName; u.LastName = model.LastName; u.EmailId = model.EmailId; u.Password = model.Password; u.IsEmailVerified = false; u.CreatedDate = DateTime.Now; u.IsActive = true; DBobj.Users.Add(u); DBobj.SaveChanges(); if (u.UserID > 0) { ModelState.Clear(); ViewBag.IsSuccess = "<p><span><i class='fas fa-check-circle'></i></span> Your account has been successfully created </p>"; TempData["name"] = model.FirstName; // Email Verification Link var activationCode = model.Password; var verifyUrl = "/User/VerifyAccount/" + activationCode; var activationlink = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl); // Sending Email EmailVerification.SendVerifyLinkEmail(u, activationlink); ViewBag.Title = "NotesMarketPlace"; @TempData["UserName"] = model.FirstName.ToString(); return(RedirectToAction("emailverification", "User")); } } } return(View()); } catch (Exception e) { return(View()); } }
public ActionResult RegisterConfirm(int regID) { using (var db = new NotesMarketPlaceEntities()) { Users user = db.Users.FirstOrDefault(x => x.ID == regID); user.IsEmailVerified = true; user.CreatedBy = user.ID; user.ModifiedDate = DateTime.Now; user.ModifiedBy = user.ID; db.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
//email template public void forallowdownload(string userName, string buyerName) { string body = System.IO.File.ReadAllText(HostingEnvironment.MapPath("~/EmailTemplate/") + "RequestForAllowDownload" + ".cshtml"); using (var context = new NotesMarketPlaceEntities()) { body = body.Replace("@ViewBag.userName", userName); body = body.Replace("@ViewBag.buyerName", buyerName); body = body.ToString(); BuildEmailVerifyTemplate(body, "*****@*****.**", buyerName); //usr email address } }