コード例 #1
0
        public ActionResult SignUpMethod(Registration objUsr)
        {
            objUsr.EmailVerification = false;
            var IsExists = IsEmailExists(objUsr.Email);

            if (IsExists)
            {
                ModelState.AddModelError("EmailExists", "Email Already Exists");
                return(View());
            }

            objUsr.ActivetionCode = Guid.NewGuid();

            objUsr.Password = MitProjectAssignment.Models.encryptPassword.textToEncrypt(objUsr.Password);
            objCon.Registration.Add(objUsr);
            objCon.SaveChanges();
            SendEmailToUser(objUsr.Email, objUsr.ActivetionCode.ToString());
            var Message = "Registration Completed. Please Check Your Email :" + objUsr.Email;

            ViewBag.Message = Message;
            return(View("Email_Verification"));
        }
コード例 #2
0
        public ActionResult AddNotes(AddNotesViewModels xyz)
        {
            if (ModelState.IsValid)
            {
                // create seller note object
                SellerNotes abc = new SellerNotes();


                var user = Context.Registration.FirstOrDefault(x => x.Email == User.Identity.Name);
                abc.Status         = Context.ReferenceData.Where(x => x.Value.ToLower() == "draft").Select(x => x.ID).FirstOrDefault();
                abc.SellerID       = user.UserId;
                abc.Title          = xyz.Title.Trim();
                abc.Country        = xyz.Country;
                abc.Category       = xyz.Category;
                abc.NoteType       = xyz.NoteType;
                abc.NumberofPages  = xyz.NumberofPages;
                abc.Description    = xyz.Description.Trim();
                abc.UniversityName = xyz.UniversityName.Trim();

                abc.Course     = xyz.Course.Trim();
                abc.CourseCode = xyz.CourseCode.Trim();
                abc.Professor  = xyz.Professor.Trim();
                abc.IsPaid     = xyz.IsPaid;
                if (abc.IsPaid)
                {
                    abc.SellingPrice = xyz.SellingPrice;
                }
                else
                {
                    abc.SellingPrice = 0;
                }

                abc.IsActive = true;
                Context.SellerNotes.Add(abc);

                try
                {
                    Context.SaveChanges();
                }
                catch (Exception ex)
                {
                }
                //


                // add note in database and save



                // get seller note
                abc = Context.SellerNotes.Find(abc.ID);

                // if display picture is not null then save picture into directory and directory path into database
                if (xyz.DisplayPicture != null)
                {
                    string displaypicturefilename = System.IO.Path.GetFileName(xyz.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + user.UserId + "/" + abc.ID + "/";
                    CreateDirectoryIfMissing(displaypicturepath);
                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    abc.DisplayPicture = displaypicturepath + displaypicturefilename;
                    xyz.DisplayPicture.SaveAs(displaypicturefilepath);
                }

                // if note preview is not null then save picture into directory and directory path into database
                if (xyz.NotesPreview != null)
                {
                    string notespreviewfilename = System.IO.Path.GetFileName(xyz.NotesPreview.FileName);
                    string notespreviewpath     = "~/Members/" + user.UserId + "/" + abc.ID + "/";
                    CreateDirectoryIfMissing(notespreviewpath);
                    string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename);
                    abc.NotesPreview = notespreviewpath + notespreviewfilename;
                    xyz.NotesPreview.SaveAs(notespreviewfilepath);
                }

                // update note preview path and display picture path and save changes
                //   Context.SellerNotes.Add(abc);
                //Context.Entry(abc).Property(x => x.DisplayPicture).IsModified = true;
                //Context.Entry(abc).Property(x => x.NotesPreview).IsModified = true;
                Context.SaveChanges();

                // attachement files
                foreach (HttpPostedFileBase file in xyz.UploadNotes)
                {
                    // check if file is null or not
                    if (file != null)
                    {
                        // save file in directory
                        string notesattachementfilename = System.IO.Path.GetFileName(file.FileName);
                        string notesattachementpath     = "~/Members/" + user.UserId + "/" + abc.ID + "/Attachements/";
                        CreateDirectoryIfMissing(notesattachementpath);
                        string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                        file.SaveAs(notesattachementfilepath);

                        // create object of sellernotesattachement
                        SellerNotesAttachments notesattachements = new SellerNotesAttachments
                        {
                            NoteID   = abc.ID,
                            FileName = notesattachementfilename,
                            FilePath = notesattachementpath,

                            IsActive = true
                        };

                        // save seller notes attachement
                        Context.SellerNotesAttachments.Add(notesattachements);
                        Context.SaveChanges();
                    }
                }
                return(RedirectToAction("SignUp", "SignUpMethod"));
            }
            // if model state is not valid
            else
            {
                // create object of xyz
                AddNotesViewModels viewModel = new AddNotesViewModels
                {
                    NoteCategoryList = Context.NoteCategories.ToList(),
                    NoteTypeList     = Context.NoteTypes.ToList(),
                    CountryList      = Context.Countrie.ToList()
                };

                return(View(viewModel));
            }
        }
コード例 #3
0
        public ActionResult UserProfile(UserProfileModel userprofilemodel)
        {
            var user = dbobj.Registration.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (userprofilemodel.ProfilePicture != null)
                {
                    var PicSize = userprofilemodel.ProfilePicture.ContentLength;
                    if (PicSize > 10 * 1024 * 1024)
                    {
                        ModelState.AddModelError("Profile_Picture", "Image size is 10MB");

                        userprofilemodel.CountryList = dbobj.Countrie.Where(x => x.IsActive == true).ToList();
                        userprofilemodel.GenderList  = dbobj.ReferenceData.Where(x => x.RefCategory == "Gender" && x.IsActive == true).ToList();
                        return(View(userprofilemodel));
                    }
                }


                var profile = dbobj.UserProfile.Where(x => x.UserId == user.UserId).FirstOrDefault();

                //edit profile

                if (profile != null)
                {
                    profile.DOB    = userprofilemodel.DOB;
                    profile.Gender = userprofilemodel.Gender;
                    profile.Phone_number___Country_Code = userprofilemodel.CountryCode.Trim();
                    profile.phone_number   = userprofilemodel.PhoneNumber.Trim();
                    profile.Address_Line_1 = userprofilemodel.Address_Line_1.Trim();
                    profile.Address_Line_2 = userprofilemodel.Address_Line_2.Trim();
                    profile.City           = userprofilemodel.City.Trim();
                    profile.State          = userprofilemodel.State.Trim();
                    profile.Zip_Code       = userprofilemodel.Zip_Code.Trim();
                    profile.Country        = userprofilemodel.Country.Trim();
                    profile.University     = userprofilemodel.University.Trim();
                    profile.College        = userprofilemodel.College.Trim();

                    //delete old profile pic
                    if (userprofilemodel.ProfilePicture != null && profile.Profile_Picture != null)
                    {
                        string   path = Server.MapPath(profile.Profile_Picture);
                        FileInfo file = new FileInfo(path);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    // if user upload profile picture then save it and store path in database

                    if (userprofilemodel.ProfilePicture != null)
                    {
                        string Profilepicturefilename = System.IO.Path.GetFileName(userprofilemodel.ProfilePicture.FileName);
                        string Profilepicturepath     = "~/Members/" + user.UserId + "/" + profile.UserId + "/";
                        CreateDirectoryIfMissing(Profilepicturepath);
                        string displaypicturefilepath = Path.Combine(Server.MapPath(Profilepicturepath), Profilepicturefilename);
                        profile.Profile_Picture = Profilepicturepath + Profilepicturefilename;
                        userprofilemodel.ProfilePicture.SaveAs(displaypicturefilepath);
                    }

                    dbobj.Entry(profile).State = EntityState.Modified;
                    dbobj.SaveChanges();

                    user.FirstName          = userprofilemodel.FirstName.Trim();
                    user.LastName           = userprofilemodel.LastName.Trim();
                    dbobj.Entry(user).State = EntityState.Modified;
                    dbobj.SaveChanges();
                }

                // new userprofile

                else
                {
                    UserProfile userProfile = new UserProfile();

                    userProfile.UserId = user.UserId;
                    userProfile.DOB    = userprofilemodel.DOB;
                    userProfile.Gender = userprofilemodel.Gender;
                    userProfile.Phone_number___Country_Code = userprofilemodel.CountryCode.Trim();
                    userProfile.phone_number   = userprofilemodel.PhoneNumber;
                    userProfile.Address_Line_1 = userprofilemodel.Address_Line_1;
                    userProfile.Address_Line_2 = userprofilemodel.Address_Line_2;
                    userProfile.City           = userprofilemodel.City;
                    userProfile.State          = userprofilemodel.State;
                    userProfile.SecondaryEmail = user.Email;
                    userProfile.Zip_Code       = userprofilemodel.Zip_Code;
                    userProfile.Country        = userprofilemodel.Country;
                    userProfile.University     = userprofilemodel.University;
                    userProfile.College        = userprofilemodel.College;

                    if (userprofilemodel.ProfilePicture != null)
                    {
                        /*string Profilepicturefilename = System.IO.Path.GetFileName(userprofilemodel.ProfilePicture.FileName);
                         * string Profilepicturepath = "~/Members/" + user.UserId + "/";
                         * CreateDirectoryIfMissing(Profilepicturepath);
                         * string displaypicturefilepath = Path.Combine(Server.MapPath(Profilepicturepath), Profilepicturefilename);
                         * profile.Profile_Picture = displaypicturefilepath;
                         * userprofilemodel.ProfilePicture.SaveAs(displaypicturefilepath);*/

                        string filename           = Path.GetFileName(userprofilemodel.ProfilePicture.FileName);
                        string fileextension      = Path.GetExtension(userprofilemodel.ProfilePicture.FileName);
                        string newfilename        = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        string profilepicturepath = "~/Members/" + user.UserId + "/";
                        CreateDirectoryIfMissing(profilepicturepath);
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        userProfile.Profile_Picture = profilepicturepath + newfilename;
                        userprofilemodel.ProfilePicture.SaveAs(path);
                    }

                    dbobj.UserProfile.Add(userProfile);
                    dbobj.SaveChanges();

                    /*user.FirstName = userprofilemodel.FirstName.Trim();
                     * user.LastName = userprofilemodel.LastName.Trim();
                     * dbobj.Entry(user).State = EntityState.Modified;
                     * dbobj.SaveChanges();*/
                }

                return(RedirectToAction("SearchNote", "SearchNote"));
            }

            // for invalid ModelState

            else
            {
                userprofilemodel.CountryList = dbobj.Countrie.Where(x => x.IsActive == true).ToList();
                userprofilemodel.GenderList  = dbobj.ReferenceData.Where(x => x.RefCategory == "Gender" && x.IsActive == true).ToList();
                return(View(userprofilemodel));
            }
        }