public ActionResult SignUp([Bind(Include = "FirstName,LastName,Email,Password,ConfirmPassword")] UsersViewModel signupviewmodel) { if (ModelState.IsValid) { using (var db = new NotesMarketPlaceEntities()) { bool emailalreadyexists = db.Users.Any(x => x.Email == signupviewmodel.Email); if (emailalreadyexists) { ModelState.AddModelError("Email", "Email already registered"); return(View()); } else { //add user data Users user = new Users { RoleID = 2, FirstName = signupviewmodel.FirstName, LastName = signupviewmodel.LastName, Email = signupviewmodel.Email, Password = signupviewmodel.Password, CreatedDate = DateTime.Now, IsActive = true }; db.Users.Add(user); db.SaveChanges(); BuildEmailVerifyTemplate(user.ID); //sending email to user db.Dispose(); ViewBag.sucess = " your account has been sucessfully created."; return(View()); } } } else { return(View()); } }
public ActionResult ConfirmEmail(string userId, string pass) { var check = objUserDBEntities.tblUsers.Where(model => model.EmailID == userId).FirstOrDefault(); if (check != null) { if (check.Password.Equals(pass)) { check.IsEmailVerified = true; objUserDBEntities.SaveChanges(); objUserDBEntities.Dispose(); return(RedirectToAction("Login", "Account")); } else { return(Content("Invalid Credentials")); } } return(Content("Invalid Credentials")); }
public ActionResult AddNotes(AddNotesViewModel note, string Command) { ViewBag.navclass = "white-nav"; ViewBag.SellNotes = "active"; Users user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name); //check user enter the profile details or not bool temp = db.UserProfile.Any(x => x.UserID == user.ID); if (!temp) { return(RedirectToAction("MyProfile", "UserProfile")); } if (user != null && ModelState.IsValid) { SellerNotes sellernotes = new SellerNotes(); sellernotes.SellerID = user.ID; sellernotes.ActionedBy = user.ID; sellernotes.Title = note.Title; sellernotes.Status = Command == "Save" ? 6 : 7; //6 for draft & 7 for submit for review 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.CreatedBy = user.ID; sellernotes.IsActive = true; if (sellernotes.IsPaid) { if (sellernotes.SellingPrice == null || sellernotes.SellingPrice < 1) { ModelState.AddModelError("SellingPrice", "Enter valid Selling price"); AddNotesViewModel viewModel = GetData(); return(View(viewModel)); } } db.SellerNotes.Add(sellernotes); db.SaveChanges(); sellernotes = db.SellerNotes.Find(sellernotes.ID); if (note.DisplayPicture == null) { //get default file name string defaultFilename = Directory.GetFiles(Server.MapPath("~/Content/image/default-note-img/")).FirstOrDefault(); string finalfilename = System.IO.Path.GetFileName(defaultFilename); //defalt path if path is null string userprofilepath = "~/Content/image/default-note-img/"; sellernotes.DisplayPicture = userprofilepath + finalfilename; //store path } if (note.DisplayPicture != null) { string displaypicturefilename = System.IO.Path.GetFileName(note.DisplayPicture.FileName); //get filename string displaypicturepath = "~/Members/" + user.ID + "/" + sellernotes.ID + "/"; //path for save file CreateDirectoryIfMissing(displaypicturepath); string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename); sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename; note.DisplayPicture.SaveAs(displaypicturefilepath); } 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(); //uploaded multiple files string notesattachementpath = "~/Members/" + user.ID + "/" + sellernotes.ID + "/Attachements/"; CreateDirectoryIfMissing(notesattachementpath); foreach (var file in note.UploadNotes) { string notesattachementfilename = System.IO.Path.GetFileName(file.FileName); string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename); file.SaveAs(notesattachementfilepath); SellerNotesAttachements notesattachements = new SellerNotesAttachements { NoteID = sellernotes.ID, FileName = notesattachementfilename, FilePath = notesattachementpath, CreatedDate = DateTime.Now, CreatedBy = user.ID, IsActive = true }; db.SellerNotesAttachements.Add(notesattachements); db.SaveChanges(); } db.Dispose(); return(RedirectToAction("AddNotes", "SellNotes")); } else { if (note.IsPaid) { if (note.SellingPrice == null) { ModelState.AddModelError("SellingPrice", "Selling price is required"); } } AddNotesViewModel viewModel = GetData(); return(View(viewModel)); } }