コード例 #1
0
        public ActionResult UploadPhoto(HttpPostedFileBase upload)
        {
            if (upload != null && Identity.isAuthentication)
            {
                string dir = Server.MapPath("~/Resources/Images/Users/" + Identity.user.Id);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                string[] dirs = Directory.GetFiles(Server.MapPath("~/Resources/Images/Users/" + Identity.user.Id), "*");

                string type = upload.FileName.Split('.').Last();

                string src  = "/Resources/Images/Users/" + Identity.user.Id + "/" + cryptMD5.GetHash(dirs.Length.ToString()) + "." + type;
                string path = Server.MapPath("~" + src);

                upload.SaveAs(path);

                UserPhotoDTO userPhoto = UserPhotoServices.GetAll().FirstOrDefault(x => x.MainPhoto && x.UserId == Identity.user.Id);
                if (userPhoto != null)
                {
                    userPhoto.MainPhoto = false;
                    UserPhotoServices.Update(userPhoto);
                }

                userPhoto           = new UserPhotoDTO();
                userPhoto.MainPhoto = true;
                userPhoto.SRC       = src;
                userPhoto.UserId    = Identity.user.Id;
                UserPhotoServices.Create(userPhoto);
            }

            return(RedirectToAction("Profile"));
        }
コード例 #2
0
        public static void Create(UserPhotoDTO userPhotoDTO)
        {
            UserPhoto userPhoto = MapperTransform <UserPhoto, UserPhotoDTO> .ToEntity(userPhotoDTO);

            Database.UserPhotos.Create(userPhoto);
            Database.Save();
        }
コード例 #3
0
        public static void Update(UserPhotoDTO userPhotoDTO)
        {
            UserPhoto userPhoto = Database.UserPhotos.Get(userPhotoDTO.Id);

            userPhoto.MainPhoto = userPhotoDTO.MainPhoto;
            userPhoto.SRC       = userPhotoDTO.SRC;
            userPhoto.UserId    = userPhotoDTO.UserId;
            Database.UserPhotos.Update(userPhoto);
            Database.Save();
        }