Beispiel #1
0
        public IActionResult Post([FromBody] ItemItem value)
        {
            if (value == null)
            {
                return(BadRequest());
            }
            DBAction injj  = new DBAction();
            ICache   cache = new ICache();

            var state = 0;

            ItemItem item = new ItemItem();

            item.VoteId     = value.VoteId;
            item.Desc       = value.Desc;
            item.DescPicUrl = value.DescPicUrl;
            item.UserId     = value.UserId;
            item.Token      = value.Token;

            string userId;

            if ((userId = cache.GetHash(value.Token, "session")) == null)
            {
                return(BadRequest());
            }

            try
            {
                if (injj.CheckVoteBelongToUser(uint.Parse(userId), value.VoteId) && injj.InsertItem(item))
                {
                    state = 1;
                }
            }
            catch
            {
                return(BadRequest());
            }


            var data = new
            {
                State = state,
            };

            var json = JObject.FromObject(data);

            return(new ObjectResult(json));
        }
Beispiel #2
0
        public IActionResult Put([FromBody] ItemItem value)
        {
            if (value == null)
            {
                return(BadRequest());
            }
            DBAction injj  = new DBAction();
            var      state = 0;

            ICache cache = new ICache();
            string userId;

            if ((userId = cache.GetHash(value.Token, "session")) == null)
            {
                return(BadRequest());
            }
            try
            {
                if (injj.CheckVoteBelongToUser(uint.Parse(userId), value.VoteId) && injj.checkItemsInVote(value.VoteId, value.ItemId) && injj.UpdateItenItem(value))
                {
                    state = 1;
                }
            }
            catch
            {
                return(BadRequest());
            }


            var data = new
            {
                State = state,
            };

            var json = JObject.FromObject(data);

            return(new ObjectResult(json));
        }
Beispiel #3
0
        public IActionResult Put([FromBody] VoteItem value)
        {
            if (value == null)
            {
                return(BadRequest());
            }
            DBAction injj  = new DBAction();
            var      state = 0;

            ICache cache = new ICache();

            if (cache.GetHash(value.Token, "session") == value.UserBelong.ToString() && injj.CheckVoteBelongToUser(value.UserBelong, value.VoteId) && injj.UpdateVoteItem(value))
            {
                state = 1;
            }
            var data = new {
                State = state
            };
            var json = JObject.FromObject(data);

            return(new ObjectResult(json));
        }