Beispiel #1
0
        public RequestResponse UpdateReward(RewardUpdate model)
        {
            if (model == null)
            {
                return(BadResponse("Request Body was empty."));
            }

            var reward = _context.Rewards.Find(model.RewardId);

            if (reward == null)
            {
                return(BadResponse("Invalid reward ID."));
            }

            var userMembership = reward.Group.GroupMembers.FirstOrDefault(gm => gm.UserId == _userId.ToString());

            if (userMembership == null || !userMembership.IsAccepted)
            {
                return(BadResponse("Invalid permissions."));
            }

            reward.GroupId         = model.GroupId;
            reward.RewardName      = model.RewardName;
            reward.Cost            = model.Cost;
            reward.NumberAvailable = model.NumberAvailable;

            if (_context.SaveChanges() != 1)
            {
                return(BadResponse("Could not save reward changes."));
            }

            return(OkResponse("Reward updated successfully."));
        }
Beispiel #2
0
        public IHttpActionResult UpdateReward(int id, RewardUpdate model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (model == null)
            {
                return(BadRequest("Request body was empty."));
            }

            if (id != model.RewardId)
            {
                return(BadRequest("Reward ID mismatch."));
            }

            var service         = GetRewardService();
            var requestResponse = service.UpdateReward(model);

            return(ValidateRequestResponse(requestResponse));
        }