public IActionResult UpdateAvatarActions(int id, [FromBody] UpdateAvatarSimple updateAvatar)
 {
     try
     {
         if (_user != null)
         {
             if (!ModelState.IsValid)
             {
                 return(BadRequest());
             }
             var avatar      = _ctx.GetAvatarById(_user.Id);
             int count       = 0;
             var finalAvatar = new AvatarEntity();
             if (updateAvatar.AvatarImgUrl != null)
             {
                 avatar.AvatarImgUrl = updateAvatar.AvatarImgUrl;
                 count++;
             }
             if (count < 1)
             {
                 return(BadRequest("No changes have been made."));
             }
             if (_ctx.UpdateAvatar(avatar))
             {
                 return(Ok(Messages(WarningType.Success, "UPDATED", _user.Id.ToString())));
             }
         }
         return(Unauthorized(Messages(WarningType.PermissionError, reference: "UPDATE", id.ToString())));
     }
     catch (Exception ex)
     {
         _logger.LogError(Messages(WarningType.LogMessage, reference: "DELETE"), ex);
         return(StatusCode(500, Messages(WarningType.ExceptionError, nameof(UpdateAvatarActions))));
     }
 }
Example #2
0
        public IActionResult ReplyToComment(int contentId, int id, [FromBody] CreateCommentForRemap reply)
        {
            // super
            try
            {
                if (_user != null || _admin != null)
                {
                    if (reply.Message.Contains('#') || reply.Message.Contains('@'))
                    {
                        var user     = new AvatarEntity();
                        var sentence = " " + reply.Message;
                        int userid   = (int)reply.AvatarId;
                        var results  = _ctx.DetectObjectType(sentence, contentId, userid);
                        // if(result != null)
                        // {
                        //     user = (AvatarEntity)result[0];
                        //     _logger.LogInformation($"This is the result - {user.Name} - {user.Id}");
                        // }
                    }

                    if (_user != null)
                    {
                        reply.AvatarId = _user.Id;
                    }

                    if (_admin != null)
                    {
                        reply.IsSuperUser = _admin.Id;
                    }
                    var comment = _ctx.GetCommentById(id);

                    reply.PostedOn           = DateTime.Now;
                    reply.CardEntityId       = contentId;
                    reply.ReplyToCommentId   = id;
                    reply.ResponseToAvatarId = comment.AvatarId;
                    var result = _mapper.Map <CommentEntity>(reply);
                    if (_user != null)
                    {
                        if (_ctx.AddCommentByUser(result, _user.Id, commentIdToAddOn: id))
                        {
                            return(Ok($"Reply had been added by USER: {_user.Id} comment:{id}."));
                        }
                    }
                    if (_admin != null)
                    {
                        if (_ctx.AddCommentByUser(result, admin: _admin.Id, commentIdToAddOn: id))
                        {
                            return(Ok($"Reply had been added by ADMIN on comment:{id}."));
                        }
                    }
                    return(NotFound($"No REPLY has been added to comment ID:{id}"));
                }
                return(Unauthorized(Message("unautherized")));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Unable to create reply on comment: {id}.", ex);
                return(StatusCode(500, "There was an expection found at RepltToComment."));
            }
        }
Example #3
0
 public JumpRightState(AvatarEntity avatar, bool moving, bool continueJump) : base(avatar)
 {
     _moveRight      = moving;
     _continueJump   = continueJump;
     Avatar.OnGround = false;
     LoadSprite();
 }
Example #4
0
        public World(Game1 gameInit)
        {
            _game = gameInit;

            _sprites = new List <ISprite>();
            Avatar   = new AvatarEntity(new Vector2(10, 10));
            AddSprite(Avatar);
        }
Example #5
0
        public List <object> DetectObjectType(string toDetect, int contentId, int avatarId)
        {
            char[] charsToTrim = { '*', ' ', '@', '#', '/' };
            var    result      = new List <object>();
            var    user        = new AvatarEntity();
            var    tag         = new TagEntity();

            if (toDetect.Contains('@'))
            {
                var regex = new Regex(@"\s@([\w$]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                foreach (Match nameMatch in regex.Matches(toDetect))
                {
                    string item = nameMatch.Groups[0].Value;
                    if (item.Contains('@'))
                    {
                        string nameResult = item.Trim(charsToTrim);
                        user = GetAvatarById(name: nameResult);
                        result.Add(user);
                    }
                }
            }
            if (toDetect.Contains('#'))
            {
                var card   = _ctx.CardEntity.Find(contentId);
                var regex2 = new Regex(@"\s#([\w$]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                foreach (Match nameMatch in regex2.Matches(toDetect))
                {
                    string item = nameMatch.Groups[0].Value;
                    if (item.Contains('#'))
                    {
                        var    tags      = _ctx.CardEntity.Where(c => c.Id == contentId).SelectMany(t => t.Tags).ToList();
                        string tagResult = item.Trim(charsToTrim);
                        if (!tags.Any(t => t.TagItem == tagResult))
                        {
                            tag = new TagEntity()
                            {
                                Id         = 0,
                                TagItem    = tagResult,
                                ByAvatarId = avatarId,
                            };
                            card.Tags.Add(tag);
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(tag.TagItem))
                {
                    _ctx.CardEntity.Attach(card);
                    _ctx.Entry(card).State = EntityState.Modified;
                    if (_ctx.SaveChanges() > 0)
                    {
                        result.Add("Done!");
                    }
                }
            }

            return(result);
        }
Example #6
0
        public bool AddNewAvatar(AvatarEntity avatar)
        {
            if (AddFruitToAvatar(avatar) != null)
            {
                if (!Exist(avatar.CurrentIP))
                {
                    _ctx.Add(avatar);

                    return(Save());
                }
            }
            return(false);
        }
        public void ChangeAvatarTest()
        {
            var entity = new AvatarEntity();

            entity.AvatarStream = TestHelper.GetTestImageStream();

            var responseResult = WebApiClient.HttpPost(ApiEnvironment.User_ChangeAvatar_Endpoint, entity);

            Assert.AreEqual(HttpStatusCode.OK, responseResult.StatusCode);
            Assert.IsNotNullOrEmpty(responseResult.Content);

            Assert.IsTrue(responseResult.Content.ConvertEntity <string>().StartsWith("http://"));
            Console.WriteLine(responseResult.Content);
        }
Example #8
0
        public AvatarEntity AddFruitToAvatar(AvatarEntity avatar)
        {
            var profileItems = _ctx.FruitItemsEntity.ToList();

            if (profileItems != null)
            {
                var profileItem = profileItems.Where(p => p.Id == profileItems.Max(c => c.Id)).FirstOrDefault();
                avatar.Name         = profileItem.FruitName;
                avatar.AvatarImgUrl = profileItem.FruitImg;

                _ctx.FruitItemsEntity.Remove(profileItem);
                if (Save() && !(string.IsNullOrWhiteSpace(avatar.Name)))
                {
                    return(avatar);
                }
            }
            // add count for remaining tokens
            return(null);
        }
Example #9
0
        public AvatarEntity GetAvatarById(int id = 0, string ip = "", string name = "")
        {
            var avatar = new AvatarEntity();
            var result = GetAllAvatars();

            if (id > 0)
            {
                avatar = result.Where(a => a.Id == id).FirstOrDefault();
            }
            if (!string.IsNullOrWhiteSpace(ip))
            {
                avatar = result.Where(a => a.CurrentIP == ip).FirstOrDefault();
            }
            if (!string.IsNullOrWhiteSpace(name))
            {
                avatar = result.Where(a => a.Name == name).FirstOrDefault();
            }

            return(avatar);
        }
Example #10
0
        public bool CheckIn(int id = 0, string ip = "")
        {
            var avatar = new AvatarEntity();

            if (id > 0)
            {
                avatar = GetAvatarById(id);
            }

            if (!string.IsNullOrWhiteSpace(ip))
            {
                avatar = GetAvatarById(ip: ip);
            }
            avatar.LastCheckedIn = DateTime.Now;
            avatar.IsCheckedIn   = true;
            _ctx.Attach(avatar);
            _ctx.Entry(avatar).State = EntityState.Modified;

            return(Save());
        }
Example #11
0
    public void DatabaseTest()
    {
        //Given
        using (var context = new ContentContext())
        {
            // context.Database.EnsureDeleted();
            context.Database.EnsureCreated();
            var avatar = new AvatarEntity();
            context.AvatarEntity.Add(avatar);
            Debug.WriteLine($"Before save: {avatar.Id}");

            context.SaveChanges();
            Debug.WriteLine($"After save: {avatar.Id}");

            Assert.NotEqual(0, avatar.Id);
        }
        //When
        // var cards = this.ctxr.GetAllCards();
        // //Then
        // Assert.Equal(3, cards.Count());
    }
        public string ChangeAvatar([FromBody] AvatarEntity entity)
        {
            if (entity == null || string.IsNullOrEmpty(entity.AvatarStream))
            {
                return(null);
            }

            var    profile   = MvcContext.Current.UserPassport.Profile;
            string avatarUrl = ImageHelper.SaveAvatar(profile.PassportId, entity.AvatarStream);

            if (false == string.IsNullOrEmpty(avatarUrl))
            {
                profile.Avatar = avatarUrl + "?t=" + DateTime.Now.ToString("yyMMddHHmmssfff");
                var isSave = profile.Save();
                if (isSave)
                {
                    return(ImageHelper.ToAbsoluteUri(avatarUrl));
                }
            }

            return(null);
        }
Example #13
0
        public string ChangeAvatar([FromBody] AvatarEntity entity)
        {
            entity.PassportId = MvcContext.Current.UserPassport.PassportId;
            if (entity == null || string.IsNullOrEmpty(entity.AvatarStream))
            {
                return(null);
            }

            var    profile   = MvcContext.Current.UserPassport.Profile;
            string avatarUrl = ImageHelper.SaveAvatar(profile.PassportId, entity.AvatarStream);

            if (false == string.IsNullOrEmpty(avatarUrl))
            {
                profile.Avatar = avatarUrl + "?t=" + DateTime.Now.ToString("yyMMddHHmmssfff");
                var isSave = profile.Save();
                if (isSave)
                {
                    return(string.Format("{0}{1}", AppEnvironment.ResourcesSiteRoot, profile.Avatar));
                }
            }

            return(null);
        }
Example #14
0
        public IEnumerable <CommentEntity> GetCommentsByAvatar(int id = 0, bool admin = false) //
        {
            var avatar   = new AvatarEntity();
            var comments = new List <CommentEntity>();

            if (admin)
            {
                comments = _ctx.CommentEntity
                           .Include(c => c.ReplyTo)
                           .Include(l => l.Likes)
                           .Include(f => f.Flags)
                           .Where(s => s.IsSuperUser == admin)
                           .AsSingleQuery()
                           .ToList();
            }
            else
            {
                var result = GetAllAvatars();
                avatar   = result.Where(a => a.Id == id).FirstOrDefault();
                comments = avatar.Comments;
            }

            return(comments);
        }
Example #15
0
 public bool UpdateAvatar(AvatarEntity avatar)
 {
     _ctx.AvatarEntity.Attach(avatar);
     _ctx.Entry(avatar).State = EntityState.Modified;
     return(Save());
 }
Example #16
0
 public FaceLeftState(AvatarEntity avatar) : base(avatar)
 {
     Avatar.Acceleration = new Vector2(1500, Avatar.Acceleration.Y);
     LoadSprite();
 }
Example #17
0
        public IActionResult CreateComment(int contentId, [FromBody] CreateCommentForRemap createdComment)
        {
            try
            {
                if (_user != null || _admin != null)
                {
                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState));
                    }
                    if (createdComment.Message.Contains('#') || createdComment.Message.Contains('@'))
                    {
                        var user     = new AvatarEntity();
                        var sentence = " " + createdComment.Message;
                        int id       = _user.Id; /*(int)createdComment.AvatarId; */
                        var result   = _ctx.DetectObjectType(sentence, contentId, id);
                        // if(result != null)
                        // {
                        //     user = (AvatarEntity)result[0];
                        //     _logger.LogInformation($"This is the result - {user.Name} - {user.Id}");
                        // }
                    }

                    if (_admin != null)
                    {
                        createdComment.IsSuperUser = _admin.Id;
                        createdComment.AvatarId    = null;
                    }
                    if (_user != null)
                    {
                        createdComment.IsSuperUser = null;
                        createdComment.AvatarId    = _user.Id;
                    }
                    createdComment.LastUpdatedOn = DateTime.Now;
                    createdComment.PostedOn      = DateTime.Now;
                    createdComment.CardEntityId  = contentId;
                    var date         = createdComment.PostedOn;
                    var finalComment = new CommentEntity();
                    _ctx.AddCommentByUser(_mapper.Map <CommentEntity>(createdComment)); //
                    if (_admin != null)
                    {
                        var dbResult = _ctx.GetCommentsByAvatar(admin: _admin.Id);
                        finalComment = dbResult.Where(p => p.PostedOn == date).FirstOrDefault();
                    }
                    if (_user != null)
                    {
                        var dbResult = _ctx.GetCommentsByAvatar(id: _user.Id);
                        finalComment = dbResult.Where(p => p.PostedOn == date).FirstOrDefault();
                    }
                    return(CreatedAtRoute(
                               "GetComment",
                               new { contentId, id = finalComment.Id },
                               finalComment
                               ));
                }
                return(BadRequest("No User is Logged in"));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Unable to create a comment on card: {contentId}.", ex);
                return(StatusCode(500, "There was an expection found at CreateComment."));
            }
        }
Example #18
0
 protected BaseState(AvatarEntity avatar) => Avatar = avatar;
Example #19
0
 public MoveRightState(AvatarEntity avatar) : base(avatar) => LoadSprite();