public ActionResult EditMemberProfile()
        {
            InterestedPartyCompoundModel memModel = new InterestedPartyCompoundModel();

            if (Session["username"] == null)
            {
                return(RedirectToAction("SignIn", "Account"));
            }
            else
            {
                //Get username of current user logged in
                string username = Session["username"].ToString();

                //Get info of profile that is being viewed
                var generaldata         = smokeFreeDB.GeneralUser.Where(x => x.userName.Equals(username));
                var interestedPartydata = smokeFreeDB.InterestedParty.Where(x => x.userName.Equals(username));

                memModel.InterestedParties = interestedPartydata.FirstOrDefault();
                memModel.GeneralUsers      = generaldata.FirstOrDefault();

                ViewBag.bio      = interestedPartydata.FirstOrDefault().bio;
                ViewBag.username = username;
            }
            return(View(memModel));
        }
        public ActionResult EditedMemberProfile(InterestedPartyCompoundModel accountInfo)
        {
            string username = Session["username"].ToString();
            var    member   = smokeFreeDB.InterestedParty.Find(username);

            member.bio = accountInfo.InterestedParties.bio;
            var generalUser = smokeFreeDB.GeneralUser.Find(username);

            HttpPostedFileBase postedFile = Request.Files["ImageFile"];

            //If user uploads new profile picture
            if (postedFile.ContentLength > 0 && postedFile.ContentType.Contains("image"))
            {
                Stream       stream       = postedFile.InputStream;
                BinaryReader binaryReader = new BinaryReader(stream);
                byte[]       img          = binaryReader.ReadBytes((int)stream.Length);
                generalUser.profilePicture = img;
            }

            member.bio = accountInfo.InterestedParties.bio;
            smokeFreeDB.Configuration.ValidateOnSaveEnabled = false;
            smokeFreeDB.SaveChanges();

            return(RedirectToAction("MemberProfile", new { viewUsername = username, page = 1 }));
        }
예제 #3
0
        public ActionResult SignUpAsMember(InterestedPartyCompoundModel accountInfo)
        {
            if (ModelState.IsValid)
            {
                var checkUsername = db.GeneralUser.FirstOrDefault(m => m.userName == accountInfo.GeneralUsers.userName);
                var checkEmail    = db.GeneralUser.FirstOrDefault(m => m.email == accountInfo.GeneralUsers.email);

                //Convert uploaded file to byte[]
                HttpPostedFileBase postedFile   = Request.Files["ImageFile"];
                Stream             stream       = postedFile.InputStream;
                BinaryReader       binaryReader = new BinaryReader(stream);
                byte[]             img          = binaryReader.ReadBytes((int)stream.Length);

                //Check if username & email already exists
                if (checkUsername == null)
                {
                    if (checkEmail == null)
                    {
                        //Set details
                        accountInfo.GeneralUsers.password       = GetMD5(accountInfo.GeneralUsers.password);
                        accountInfo.GeneralUsers.profilePicture = img;
                        accountInfo.InterestedParties.userName  = accountInfo.GeneralUsers.userName;
                        accountInfo.InterestedParties.bio       = "";

                        //Insert into database
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.GeneralUser.Add(accountInfo.GeneralUsers);
                        db.InterestedParty.Add(accountInfo.InterestedParties);
                        db.SaveChanges();
                        return(RedirectToAction("SignUpSuccessMember"));
                    }
                    else
                    {
                        ViewData["EmailExists"] = "Email already exists";
                    }
                }
                else
                {
                    ViewData["UsernameExists"] = "Username already exists";
                }
            }
            return(View("SignUpMember"));
        }