public void HandleEvent(Event oneEvent)
        {
            var          service  = HouseService.Instence;
            var          checkIn  = service.CheckInService.FindOneById((Guid)oneEvent.Subject);
            House        theHouse = service.FindOneById(checkIn.TargetId);
            OldHouseUser user     = service.MyUserManager.FindByIdAsync((Guid)oneEvent.Sender).Result;
            //string myContent = "您关注的用户 " + user.NickName + "(" + user.UserName + ")刚刚发表了关于老房子\"" + theHouse.Name + "\"的签到\"" + checkIn.Title + "\"!";
            string        myContent = "【" + user.NickName + "(" + user.UserName + ")】到过了" + "【" + theHouse.Name + "】";
            string        title     = "我发表了新的签到";
            string        link      = "/house/Checkin/detail/" + checkIn.Id.ToString();
            List <string> picture   = new List <string>();

            if (checkIn.Asset != null)
            {
                foreach (var asset in checkIn.Asset)
                {
                    if (asset.Type == Asset.IMAGE)
                    {
                        picture.Add(asset.Path);
                    }
                }
            }
            foreach (Guid receiverId in service.GetAllFollowerUserIds(user.Id))
            {
                var msg = new Message {
                    Title = title, Text = myContent, IsBroadcast = false, MessageFrom = user.Id.ToString(), ReceiverId = receiverId, MessageType = "Feed.NewCheckIn", DestinationLink = link, Pictures = picture
                };
                service.FeedService.SendMessage(msg);
            }
            //为新check in创建者加10分
            var profile = service.ProfileService.EntityRepository.FindOneById(user.Profiles["OldHouseUserProfile"]);

            profile.AddPoint(10);
            service.ProfileService.EntityRepository.SaveOne(profile);
        }
        public OldHouseUser GetTestFackUser(string nickName, string userName, string password)
        {
            var user = MyUserManager.FindByNameAsync(userName).Result;

            if (user != null)
            {
                return(user);
            }

            user = new OldHouseUser {
                NickName     = nickName,
                UserName     = userName,
                PasswordHash = password
            };
            //todo put all oldhouse user roles in consts
            //todo use a fake user iu data base later
            user.Roles.Add("User");
            //it has no profile yet
            //todo may return a fake profile in data base
            var profile = CreateAFakeProfile();

            user.Profiles.Add(OldHouseUserProfile.PROFILENBAME, profile.Id);
            MyUserManager.CreateAsync(user).Wait();
            ProfileService.SaveOne(profile);
            return(user);
        }
Esempio n. 3
0
        public void HandleEvent(Event oneEvent)
        {
            var          service = HouseService.Instence;
            House        house   = service.FindOneById((Guid)oneEvent.Subject);
            OldHouseUser user    = service.MyUserManager.FindByIdAsync((Guid)oneEvent.Sender).Result;
            //string myContent = user.NickName + "(" + user.UserName + ")刚刚发现了新的老房子!";
            string        myContent = "【" + user.NickName + "(" + user.UserName + ")】有了新发现:【" + house.Name + "】";
            string        title     = "新的老房子";
            string        link      = "/House/detail/" + house.Id.ToString();
            List <string> picture   = new List <string>();

            if (house.Cover != null)
            {
                picture.Add(house.Cover);
            }
            var msg = new Message {
                Title = title, Text = myContent, IsBroadcast = true, MessageFrom = user.Id.ToString(), ReceiverId = Guid.Empty, MessageType = "Feed.NewHouse", DestinationLink = link, Pictures = picture
            };

            service.FeedService.SendMessage(msg);
            //为新old house创建者加20分
            var profile = service.ProfileService.EntityRepository.FindOneById(user.Profiles["OldHouseUserProfile"]);

            profile.AddPoint(20);
            service.ProfileService.EntityRepository.SaveOne(profile);
        }
Esempio n. 4
0
        public ActionResult ByFollow(string id = "")
        {
            OldHouseUser user = null;

            if (id.Equals(""))
            {
                user = AppUser;
            }
            else
            {
                user = MyService.MyUserManager.FindByIdAsync(new Guid(id)).Result;
            }
            List <OldHouseUser> follows = new List <OldHouseUser>();

            foreach (var one in MyService.MyUserManager.UserRepository.FindAll())
            {
                if (MyService.AmIFollowing(user.Id, one.Id))
                {
                    follows.Add(one);
                }
            }
            IEnumerable <UserInformationDto> users = Mapper.Map <IEnumerable <UserInformationDto> >(follows);

            ViewBag.Title = user.NickName + "的粉丝";
            ViewBag.Type  = "粉丝";
            return(View("Follow", users));
        }
        /// <summary>
        /// just the create user method in the jtext103Identity, but with profile added
        //
        /// </summary>
        /// <param name="user">the oldhouse user</param>
        /// <param name="profileNames">you can indecate a list of new profile name</param>
        /// <returns></returns>
        public async Task <IdentityResult> CreateUserWithProfile(OldHouseUser user, HashSet <string> profileNames)
        {
            //default user role
            user.Roles.Add("User");
            var avatarName = "defaultAvatar_boy_";

            if (user.sex == "female")
            {
                avatarName = "defaultAvatar_girl_";
            }
            var rnd = new Random();

            avatarName += rnd.Next(1, 6).ToString() + ".jpg";
            user.Avatar = avatarName;

            var result = await MyUserManager.CreateAsync(user);

            //only when the user is added then can we add profiels
            if (result.IsSuccessful)
            {
                //done add userId in profile
                user.Profiles = CreateNewProfile(profileNames, user.Id);
                await MyUserManager.UpdateAsync(user);
            }
            return(result);
        }
Esempio n. 6
0
        public ActionResult GetMyFollow(string id = "")
        {
            OldHouseUser user = null;

            if (id.Equals(""))
            {
                user = AppUser;
            }
            else
            {
                user = MyService.MyUserManager.FindByIdAsync(new Guid(id)).Result;
            }
            //foreach (var followId in MyService.GetAllFollowingIds(user.Id))
            //{
            //    OldHouseUser followUser = MyService.MyUserManager.FindByIdAsync(MyService.ProfileService.FindOneById(followId).UserId).Result;
            //    follows.Add(followUser);
            //}
            UserInformationDto model = Mapper.Map <UserInformationDto>(user);

            if (AppUser != null && model.Id.Equals(AppUser.Id))
            {
                model.Who = "我";
            }
            ViewBag.Visitor = model;
            IEnumerable <UserDisplayDto> users = Mapper.Map <IEnumerable <UserDisplayDto> >(MyService.GetAllFollowingUser(user.Id));

            ViewBag.Title = user.NickName + "的关注";
            ViewBag.Type  = "关注";
            return(View("Follow", users));
        }
Esempio n. 7
0
        public HttpResponseMessage UploadAvatar()
        {
            Guid         userId      = new Guid(User.Identity.GetUserId());
            OldHouseUser user        = MyService.MyUserManager.FindByIdAsync(userId).Result;
            var          httpRequest = HttpContext.Current.Request;

            if (httpRequest.Files.Count != 1)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("请求不合法", System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
                });
            }
            var    postedFile = httpRequest.Files[0];
            string path       = user.Id.ToString() + postedFile.FileName.Substring(postedFile.FileName.LastIndexOf(".")); //相对路径+图像名称+图像格式
            string filePath   = HttpContext.Current.Server.MapPath("~/Content/Images/avatar/" + path);                    //绝对路径

            string oldAvatarPath = HttpContext.Current.Server.MapPath("~/Content/Images/avatar/" + user.Avatar);          //根据相应Profile获得原图像相对路径

            if (File.Exists(oldAvatarPath) && !oldAvatarPath.ToLower().Contains("default"))                               //如果原图像存在且不为系统默认头像,则删除
            {
                File.Delete(oldAvatarPath);
            }

            Stream fileStream = postedFile.InputStream;

            HandleImageService.CutForCustom(fileStream, filePath, 256, 256, 75);//剪裁为256*256并保存图像到本地
            fileStream.Close();

            user.Avatar = path;//将新图像相对路径保存到当前用户的相应Profile中
            MyService.MyUserManager.UserRepository.SaveOne(user);

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
Esempio n. 8
0
 public void SetUpUser()
 {
     try
     {
         AppUser = MyService.MyUserManager.FindByIdAsync(Guid.Parse(User.Identity.GetUserId())).Result;
     }
     catch (Exception)
     {
     }
 }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 public void SetUpUser()
 {
     try
     {
         AppUser      = MyService.MyUserManager.FindByIdAsync(Guid.Parse(User.Identity.GetUserId())).Result;
         ViewBag.User = Mapper.Map <UserDisplayDto>(AppUser);
     }
     catch (Exception)
     {
     }
 }
Esempio n. 10
0
        public ActionResult GetHomePage(string id = "")
        {
            OldHouseUser user = null;

            if (id.Equals(""))
            {
                user = AppUser;
            }
            else
            {
                user = MyService.MyUserManager.FindByIdAsync(new Guid(id)).Result;
            }
            UserInformationDto model = Mapper.Map <UserInformationDto>(user);
            int count = MyService.GetProfile(user.Profiles[OldHouseUserProfile.PROFILENBAME]).FollowerCount;

            if (AppUser != null && model.Id.Equals(AppUser.Id))
            {
                model.Who = "我";
            }
            ViewBag.Title   = model.NickName + "的主页";
            ViewBag.Visitor = model;
            return(View(model));
        }