public static ObjectId ConvertBoRefToObjectId(BoRef id)
 {
     if (id == null || id.IsEmpty())
     {
         return ObjectId.GenerateNewId();
     }
     return new ObjectId(id.Value.Replace("\"", ""));
 }
Пример #2
0
 public bool Delete(UserModel user, BoRef micropostId)
 {
     var userBo = _repository.FindById<UserBo>(user.Id);
     var micropostOid = ObjectIdConverter.ConvertBoRefToObjectId(micropostId);
     MicropostBo micropostBo = userBo.Microposts.FirstOrDefault(m => m.Id == micropostOid);
     if (micropostBo != null)
     {
         userBo.Microposts.Remove(micropostBo);
         return _repository.Save(userBo);
     }
     return false;
 }
Пример #3
0
 public bool Follow(BoRef loggedId, UserModel userToFollow)
 {
     bool result = false;
     var loggedUserBo = _repository.FindById<UserBo>(loggedId);
     var followUserBo = _repository.FindById<UserBo>(userToFollow.Id);
     if (loggedUserBo != null && followUserBo != null)
     {
         //TODO: Transactional?
         if (!loggedUserBo.Following.Contains(followUserBo.Id))
         {
             loggedUserBo.Following.Add(followUserBo.Id);
             result = _repository.Save(loggedUserBo);
         }
         if (result && !followUserBo.Followers.Contains(loggedUserBo.Id))
         {
             followUserBo.Followers.Add(loggedUserBo.Id);
             result = _repository.Save(followUserBo);
         }
     }
     return result;
 }
Пример #4
0
        public ActionResult Follow(string id)
        {
            var loggedId = new BoRef(User.Identity.Name);

            var userId = new BoRef(id);
            UserModel user = _userBS.GetUser(userId);
            var micropostsForUser = new MicropostsForUserModel { User = user };

            bool followed = user.Followers.Any(r => r.Value == loggedId.Value);
            bool result = (followed)
                              ? _userBS.Unfollow(loggedId, user)
                              : _userBS.Follow(loggedId, user);
            if (result)
            {
                user = _userBS.GetUser(userId);
                micropostsForUser = _micropostBS.GetMicropostsForUser(user);
            }
            else
            {
                ViewBag.FlashMessage = "Follow/Unfollow failure!";
                ViewBag.FlashClass = "error";
            }
            return View("Show", micropostsForUser);
        }
Пример #5
0
 public UserModel GetUser(BoRef id)
 {
     var userBo = _repository.FindById<UserBo>(id);
     return Mapper.Map<UserBo, UserModel>(userBo);
 }
Пример #6
0
 public string GetStoredPasswordSalt(BoRef id)
 {
     var userBo = _repository.FindById<UserBo>(id);
     return userBo != null ? userBo.PasswordSalt : string.Empty;
 }
Пример #7
0
 public ActionResult Edit()
 {
     var loggedId = new BoRef(User.Identity.Name);
     UserModel user = _userBS.GetUser(loggedId);
     return View("Settings", user);
 }
Пример #8
0
 protected ModelWithId()
 {
     Id = new BoRef();
 }