public ActionResult forget(UserForget userForget) { if (ModelState.IsValid) { bool valid = db.Users.Any(m => m.EmailID == userForget.emailAddress); if (valid) { string _allowedChar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int length = _allowedChar.Length; Random rand = new Random(); char[] password = new char[5]; for (int i = 0; i < 5; i++) { password[i] = _allowedChar[(int)(length * rand.NextDouble())]; } User user = db.Users.Where(m => m.EmailID == userForget.emailAddress).FirstOrDefault(); string pass = new string(password); user.Password = pass; db.Users.Attach(user); db.Entry(user).Property(m => m.Password).IsModified = true; db.SaveChanges(); buildEmailTamplateforget(user.id); ViewBag.success = "letter sent"; return(View()); } else { TempData["invalidEmail"] = "Wrong Email Adress"; return(View()); } } return(View()); }
public ActionResult UserProfile(UserProfileViewModel user) { user.genderList = db.genders.ToList(); user.countryList = db.Countries.Where(m => m.IsActive == true).ToList(); if (ModelState.IsValid) { User usrname = db.Users.Where(m => m.EmailID == System.Web.HttpContext.Current.User.Identity.Name).FirstOrDefault(); var userprofile = db.UserProfiles.Where(m => m.UserID == usrname.id).SingleOrDefault(); if (userprofile != null) { usrname.FirstName = user.FirstName; usrname.LastName = user.LastName; db.Users.Attach(usrname); db.Entry(usrname).Property(m => m.FirstName).IsModified = true; db.Entry(usrname).Property(m => m.LastName).IsModified = true; db.SaveChanges(); userprofile.AddressLine1 = user.Address1; userprofile.AddressLine2 = user.Address2; userprofile.City = user.city; userprofile.College = user.college; userprofile.Country = user.usrCountry; userprofile.ModifiedDate = DateTime.Now; userprofile.ModifiedBy = usrname.id; userprofile.DOB = user.BirthDate; userprofile.Gender = user.gender; userprofile.PhoneNumber = user.PhonNumber; userprofile.PhoneNumber_code = user.countryCode; if (user.profilepicture != null) { string filename = System.IO.Path.GetFileName(user.profilepicture.FileName); filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-" + filename; string FilePath = "~/Membere/" + usrname.id + "/"; bool exist = Directory.Exists(Server.MapPath(FilePath)); if (!exist) { Directory.CreateDirectory(Server.MapPath(FilePath)); } userprofile.ProfilePicture = FilePath + filename; user.profilepicPath = Path.Combine(Server.MapPath(FilePath), (filename)); user.profilepicture.SaveAs(user.profilepicPath); } else { userprofile.ProfilePicture = user.profilepicPath; } userprofile.State = user.state; userprofile.University = user.University; userprofile.ZipCode = user.zipCode; db.UserProfiles.Attach(userprofile); db.Entry(userprofile).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Serch_note", "Home")); } else { usrname.FirstName = user.FirstName; usrname.LastName = user.LastName; db.Users.Attach(usrname); db.Entry(usrname).Property(m => m.FirstName).IsModified = true; db.Entry(usrname).Property(m => m.LastName).IsModified = true; db.SaveChanges(); UserProfile profile = new UserProfile(); profile.UserID = usrname.id; profile.DOB = user.BirthDate; profile.Gender = user.gender; if ((user.PhonNumber == null && user.countryCode == null) || (user.PhonNumber != null && user.countryCode != null)) { profile.PhoneNumber_code = user.countryCode; profile.PhoneNumber = user.PhonNumber; } if (user.profilepicture != null) { string filename = System.IO.Path.GetFileName(user.profilepicture.FileName); filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-" + filename; string FilePath = "~/Membere/" + usrname.id + "/"; bool exist = Directory.Exists(Server.MapPath(FilePath)); if (!exist) { Directory.CreateDirectory(Server.MapPath(FilePath)); } profile.ProfilePicture = FilePath + filename; user.profilepicPath = Path.Combine(Server.MapPath(FilePath), (filename)); user.profilepicture.SaveAs(user.profilepicPath); } profile.AddressLine1 = user.Address1; profile.AddressLine2 = user.Address2; profile.City = user.city; profile.State = user.state; profile.ZipCode = user.zipCode; profile.Country = user.usrCountry; profile.University = user.University; profile.College = user.college; profile.CreatedDate = DateTime.Now; profile.CreatedBy = usrname.id; db.UserProfiles.Add(profile); db.SaveChanges(); return(RedirectToAction("Serch_note", "Home")); } } return(View(user)); }
public ActionResult AddNote(AddNoteModel note, string Command) { ViewBag.Class = "white-nav"; User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name); if (user != null && ModelState.IsValid) { SellerNote sellernotes = new SellerNote(); // Save note info in Database sellernotes.SellerID = user.ID; sellernotes.Title = note.Title; sellernotes.Status = Command == "Save" ? 1 : 2; sellernotes.Category = note.Category; sellernotes.NoteType = note.NoteType; sellernotes.NumberofPages = note.NumberofPages; sellernotes.Description = note.Description; sellernotes.UniversityName = note.UniversityName; sellernotes.Country = note.Country; sellernotes.Course = note.Course; sellernotes.CourseCode = note.CourseCode; sellernotes.Professor = note.Professor; sellernotes.IsPaid = note.IsPaid; sellernotes.SellingPrice = sellernotes.IsPaid == false ? 0 : note.SellingPrice; sellernotes.CreatedDate = DateTime.Now; sellernotes.ModifiedDate = DateTime.Now; sellernotes.CreatedBy = user.ID; sellernotes.ModifiedBy = user.ID; sellernotes.IsActive = true; // If seller add unvalid price if (note.IsPaid) { if (note.SellingPrice == null || note.SellingPrice < 1) { ModelState.AddModelError("SellingPrice", "Enter valid Selling price"); AddNoteModel viewModel = GetDD(); return(View(viewModel)); } } if (note.UploadNotes[0] == null) { ModelState.AddModelError("UploadNotes", "Enter Note"); AddNoteModel viewModel = GetDD(); return(View(viewModel)); } db.SellerNotes.Add(sellernotes); db.SaveChanges(); sellernotes = db.SellerNotes.Find(sellernotes.ID); //save note picture if User add if (note.DisplayPicture != null) { string displaypicturefilename = Path.GetFileName(note.DisplayPicture.FileName); string displaypicturepath = "~/Members/" + user.ID + "/" + sellernotes.ID + "/"; CreateDirectoryIfMissing(displaypicturepath); string displaypicturefilepath = Path.Combine(Server.MapPath("~/Members/" + user.ID + "/" + sellernotes.ID + "/"), displaypicturefilename); sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename; note.DisplayPicture.SaveAs(displaypicturefilepath); } else { var filepath = db.SystemConfigurations.Where(x => x.Name == "DefaultNoteDisplayPicture").FirstOrDefault(); sellernotes.DisplayPicture = filepath.Value; } //save note preview if (note.NotesPreview != null) { string notespreviewfilename = System.IO.Path.GetFileName(note.NotesPreview.FileName); string notespreviewpath = "~/Members/" + user.ID + "/" + sellernotes.ID + "/"; CreateDirectoryIfMissing(notespreviewpath); string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename); sellernotes.NotesPreview = notespreviewpath + notespreviewfilename; note.NotesPreview.SaveAs(notespreviewfilepath); } db.SellerNotes.Attach(sellernotes); db.Entry(sellernotes).Property(x => x.DisplayPicture).IsModified = true; db.Entry(sellernotes).Property(x => x.NotesPreview).IsModified = true; db.SaveChanges(); //save note file if (note.UploadNotes[0] != null) { foreach (HttpPostedFileBase file in note.UploadNotes) { if (file != null) { string notesattachementfilename = System.IO.Path.GetFileName(file.FileName); string notesattachementpath = "~/Members/" + user.ID + "/" + sellernotes.ID + "/Attachements/"; CreateDirectoryIfMissing(notesattachementpath); string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename); note.NotesPreview.SaveAs(notesattachementfilepath); //save note file into SellerNotesAttachement table SellerNotesAttachement notesattachements = new SellerNotesAttachement { NoteID = sellernotes.ID, FileName = notesattachementfilename, FilePath = notesattachementpath + notesattachementfilename, CreatedDate = DateTime.Now, CreatedBy = user.ID, ModifiedDate = DateTime.Now, ModifiedBy = user.ID, IsActive = true }; db.SellerNotesAttachements.Add(notesattachements); db.SaveChanges(); } } } db.Dispose(); return(RedirectToAction("Index", "SellNote")); } else { AddNoteModel viewModel = GetDD(); return(View(viewModel)); } }