예제 #1
0
        // GET: /Account/UserProfile/2
        public ActionResult UserProfile(int?id, string a)
        {
            if (id == null)
            {
                id = db_Accounts.GetUserIDX();
            }

            //security validation: only admins can (only allow site admin or user to edit their own profile)
            if (!User.IsInRole("Admins") && a == "a")
            {
                return(RedirectToAction("AccessDenied", "Home"));
            }

            //security validation (only allow site admin or user to edit their own profile)
            if ((!User.IsInRole("Admins")) && (id != db_Accounts.GetUserIDX()))
            {
                return(RedirectToAction("AccessDenied", "Home"));
            }


            var        model = new vmAccountUserProfile();
            T_OE_USERS u     = db_Accounts.GetT_OE_USERSByIDX(id ?? 0);

            if (u != null)
            {
                model.UserIDX        = u.USER_IDX;
                model.UserID         = u.USER_ID;
                model.FName          = u.FNAME;
                model.LName          = u.LNAME;
                model.Email          = u.EMAIL;
                model.Phone          = u.PHONE;
                model.PhoneExt       = u.PHONE_EXT;
                model.OrgIDX         = u.ORG_IDX;
                model.JobTitle       = u.JOB_TITLE;
                model.LinkedIn       = u.LINKEDIN;
                model.NodeAdmin      = u.NODE_ADMIN;
                model.HasAvatar      = (u.USER_AVATAR != null);
                model.ImageUniqueStr = (u.MODIFY_DT ?? u.CREATE_DT).ConvertOrDefault <DateTime>().Ticks.ToString();
                model.ActInd         = u.ACT_IND;
                model.uListInd       = a;
                model.ExcludeBadges  = u.EXCLUDE_POINTS_IND;


                //expertise
                model.SelectedExpertise = db_EECIP.GetT_OE_USER_EXPERTISE_ByUserIDX(id ?? 0);
                model.AllExpertise      = db_EECIP.GetT_OE_USER_EXPERTISE_ByUserIDX_All(id ?? 0).Select(x => new SelectListItem {
                    Value = x, Text = x
                });

                //org name
                T_OE_ORGANIZATION org = db_Ref.GetT_OE_ORGANIZATION_ByID(model.OrgIDX.ConvertOrDefault <Guid>());
                if (org != null)
                {
                    model.OrgName = org.ORG_NAME;
                }
            }

            return(View(model));
        }
예제 #2
0
        public ActionResult UserProfile(vmAccountUserProfile model)
        {
            //security validation (only allow site admin or user to edit their own profile)
            if ((!User.IsInRole("Admins")) && (model.UserIDX != db_Accounts.GetUserIDX()))
            {
                return(RedirectToAction("AccessDenied", "Home"));
            }

            if (ModelState.IsValid)
            {
                if (model.UserIDX > 0)
                {
                    var strippedPhone = Regex.Replace(model.Phone ?? "", "[^0-9]", "");

                    int SuccID = db_Accounts.UpdateT_OE_USERS(model.UserIDX, null, null, model.FName, model.LName, model.Email, null, null, null, null, strippedPhone, model.PhoneExt, null, null, model.OrgIDX, model.JobTitle);

                    //update user experience
                    db_EECIP.DeleteT_OE_USER_EXPERTISE(model.UserIDX);
                    foreach (string expertise in model.SelectedExpertise ?? new List <string>())
                    {
                        db_EECIP.InsertT_OE_USER_EXPERTISE(model.UserIDX, expertise.ConvertOrDefault <int>());
                    }

                    ////avatar handling
                    //if (model.UploadImage != null)
                    //{
                    //    byte[] buffer;
                    //    using (Stream inputStream = model.UploadImage.InputStream)
                    //    {
                    //        MemoryStream memoryStream = inputStream as MemoryStream;
                    //        if (memoryStream == null)
                    //        {
                    //            memoryStream = new MemoryStream();
                    //            inputStream.CopyTo(memoryStream);
                    //        }
                    //        buffer = memoryStream.ToArray();
                    //    }
                    //    db_Accounts.UpdateT_OE_USERS_Avatar(model.UserIDX, buffer);
                    //}

                    if (SuccID > 0)
                    {
                        TempData["Success"] = "Update successful.";
                    }
                    else
                    {
                        TempData["Error"] = "Error updating data.";
                    }
                }
            }

            return(RedirectToAction("UserProfile", new { a = model.uListInd }));
        }
예제 #3
0
        // GET: /Account/UserProfile/2
        public ActionResult UserProfile(int?id, string a)
        {
            if (id == null)
            {
                id = db_Accounts.GetUserIDX();
            }
            //security validation (only allow site admin or user to edit their own profile)
            if ((!User.IsInRole("Admins")) && (id != db_Accounts.GetUserIDX()))
            {
                return(RedirectToAction("AccessDenied", "Home"));
            }


            var        model = new vmAccountUserProfile();
            T_OE_USERS u     = db_Accounts.GetT_OE_USERSByIDX(id ?? 0);

            if (u != null)
            {
                model.UserIDX  = u.USER_IDX;
                model.UserID   = u.USER_ID;
                model.FName    = u.FNAME;
                model.LName    = u.LNAME;
                model.Email    = u.EMAIL;
                model.Phone    = u.PHONE;
                model.PhoneExt = u.PHONE_EXT;
                model.OrgIDX   = u.ORG_IDX;
                model.JobTitle = u.JOB_TITLE;
                model.GetImage = u.USER_AVATAR;
                model.uListInd = a;

                //expertise
                model.SelectedExpertise = db_EECIP.GetT_OE_USER_EXPERTISE_ByUserIDX(id ?? 0);
            }

            return(View(model));
        }
예제 #4
0
        public ActionResult UserProfile(vmAccountUserProfile model)
        {
            //security validation (only allow site admin or user to edit their own profile)
            if ((!User.IsInRole("Admins")) && (model.UserIDX != db_Accounts.GetUserIDX()))
            {
                return(RedirectToAction("AccessDenied", "Home"));
            }

            if (ModelState.IsValid)
            {
                if (model.UserIDX > 0)
                {
                    var strippedPhone = Regex.Replace(model.Phone ?? "", "[^0-9]", "");
                    if ((model.LinkedIn ?? "").Contains("www"))
                    {
                        try {
                            Uri uri = new Uri(model.LinkedIn);
                            model.LinkedIn = uri.Segments.Last();
                        } catch { }
                    }

                    int SuccID = db_Accounts.UpdateT_OE_USERS(model.UserIDX, null, null, model.FName, model.LName, model.Email, model.ActInd, null, null, null, strippedPhone, model.PhoneExt, null, null, model.OrgIDX, model.JobTitle, model.LinkedIn, model.NodeAdmin, model.ExcludeBadges);

                    //update user expertise
                    db_EECIP.DeleteT_OE_USER_EXPERTISE(model.UserIDX);
                    foreach (string expertise in model.SelectedExpertise ?? new List <string>())
                    {
                        db_EECIP.InsertT_OE_USER_EXPERTISE(model.UserIDX, expertise);
                    }

                    //award profile badge
                    if (db_Accounts.GetUserIDX() == model.UserIDX)
                    {
                        db_Forum.EarnBadgeController(model.UserIDX, "UserProfile");
                    }

                    ////avatar handling
                    if (model.imageBrowes != null)
                    {
                        // ******************** VALIDATION START ********************************
                        //File too big check
                        if (model.imageBrowes.ContentLength > 10485760)
                        {
                            TempData["Error"] = "File cannot exceed 10MB";
                            return(RedirectToAction("UserProfile", new { a = model.uListInd }));
                        }

                        //invalid file extension check
                        var           fileExtension     = Path.GetExtension(model.imageBrowes.FileName);
                        List <string> allowedExtensions = new List <string> {
                            ".jpg", ".jpeg", ".png", ".bmp"
                        };
                        if (!allowedExtensions.Contains(fileExtension))
                        {
                            TempData["Error"] = "Invalid file type";
                            return(RedirectToAction("UserProfile", new { a = model.uListInd }));
                        }
                        // ******************** VALIDATION END ********************************

                        // Convert to Png
                        var outputStream = model.imageBrowes.InputStream.ConvertImage(ImageFormat.Png);

                        //save to db
                        db_Accounts.UpdateT_OE_USERS_Avatar(model.UserIDX, Utils.ConvertGenericStreamToByteArray(outputStream));

                        //save to file system
                        string fileName1 = model.UserIDX.ToString() + ".png";
                        model.imageBrowes.SaveAs(Server.MapPath("/Content/Images/Users/" + fileName1));

                        //award badge
                        if (db_Accounts.GetUserIDX() == model.UserIDX)
                        {
                            db_Forum.EarnBadgeController(model.UserIDX, "Photogenic");
                        }
                    }

                    //update azure search
                    AzureSearch.PopulateSearchIndexUsers(model.UserIDX);

                    if (SuccID > 0)
                    {
                        TempData["Success"] = "Update successful.";
                    }
                    else
                    {
                        TempData["Error"] = "Error updating data.";
                    }
                }
            }

            return(RedirectToAction("UserProfile", new { a = model.uListInd }));
        }