Exemplo n.º 1
0
        public JsonResult UploadFile()
        {
            if (Request.Files.Count.Equals(0))
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { Result = "Error" }));
            }
            try
            {
                var buApplicationUser = new BuApplicationUser();
                var user = buApplicationUser.GetByUserName(User.Identity.GetUserName());

                for (var i = 0; i < Request.Files.Count; i++)
                {
                    var poImgFile = Request.Files[i];
                    using (var binary = new BinaryReader(poImgFile.InputStream))
                        user.ProfilePhoto = binary.ReadBytes(poImgFile.ContentLength);
                }

                buApplicationUser.Update(user);

                return(Json(new { Result = "Ok" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(View());
            }
            var buApplicationUser = new BuApplicationUser();
            var user = buApplicationUser.GetByUserName(User.Identity.GetUserName());

            return(View(user));
        }
Exemplo n.º 3
0
        public FileContentResult ProfilePhoto()
        {
            if (!User.Identity.IsAuthenticated || string.IsNullOrEmpty(User.Identity.GetUserId()))
            {
                return(File(LoadDefaultProfilePhoto(), "image/png"));
            }

            var buApplicationUser = new BuApplicationUser();
            var user = buApplicationUser.GetByUserName(User.Identity.GetUserName());

            return(user?.ProfilePhoto == null?File(LoadDefaultProfilePhoto(), "image/png") : new FileContentResult(user.ProfilePhoto, "image/jpeg"));
        }
Exemplo n.º 4
0
        public JsonResult DeleteFile()
        {
            try
            {
                var buApplicationUser = new BuApplicationUser();
                var user = buApplicationUser.GetByUserName(User.Identity.GetUserName());
                user.ProfilePhoto = null;
                buApplicationUser.Update(user);

                return(Json(new { Result = "Ok" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }