public async Task <IActionResult> DeletePlayer([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var player = await _context.Players.FindAsync(id);

            if (player == null)
            {
                return(HttpResponseHelper.NotFound("No such Player found."));
            }

            player.IsEnabled = false;

            var error = await SaveChangesAsync();

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

            return(Ok(player));
        }
        public async Task <IActionResult> GetMatchRounds([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var match = await _context.Matches.Where(m => m.Id.Equals(id)).Include(m => m.Actors).FirstOrDefaultAsync();

            if (match == null)
            {
                return(HttpResponseHelper.NotFound("No such Match found."));
            }

            IList <Guid> matchActors = match.Actors.AsEnumerable().Select(a => a.Id).ToList();

            IList <MatchRound> matchRounds =
                await
                _context.MatchRounds.Where(r => matchActors.Contains(r.MatchActorId))
                .OrderBy(r => r.RoundNumber)
                .ToListAsync();

            IList <MatchRoundResponse> matchRoundResponse = new List <MatchRoundResponse>();

            foreach (var round in matchRounds)
            {
                var pushRound = false;
                var mRound    = matchRoundResponse.FirstOrDefault(r => r.RoundNumber.Equals(round.RoundNumber));
                if (mRound == null)
                {
                    mRound = new MatchRoundResponse
                    {
                        RoundNumber = round.RoundNumber,
                        Actors      = new List <MatchRoundActor>()
                    };

                    pushRound = true;
                }

                var actor = match.Actors.FirstOrDefault(a => a.Id.Equals(round.MatchActorId));
                if (actor != null)
                {
                    var matchRoundActor = new MatchRoundActor
                    {
                        ActorId   = actor.ActorId,
                        Score     = round.Score,
                        DateScore = round.DateScore
                    };

                    mRound.Actors.Add(matchRoundActor);
                }

                if (pushRound)
                {
                    matchRoundResponse.Add(mRound);
                }
            }

            return(Ok(matchRoundResponse));
        }
예제 #3
0
        public async Task <IActionResult> DeleteAttributeType([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var type = await _context.AttributeTypes.FindAsync(id);

            if (type == null)
            {
                return(HttpResponseHelper.NotFound("No Attribute Type found."));
            }

            _context.AttributeTypes.Remove(type);

            var error = await SaveChangesAsync();

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

            return(Ok(type));
        }
        public async Task <IActionResult> FinishMatch([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var match = await _context.Matches.FindAsync(id);

            if (match == null)
            {
                return(HttpResponseHelper.NotFound("No Match found."));
            }

            match.IsFinished = true;

            var error = await SaveChangesAsync();

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

            return(Ok(match));
        }
        public async Task <IActionResult> PostActionRelation([FromBody] ActionRelation actionRelation)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }
            if (actionRelation.ActionId != Guid.Empty)
            {
                var actTest = await _context.Actions.FindAsync(actionRelation.ActionId);

                if (actTest == null)
                {
                    return(HttpResponseHelper.NotFound("Invalid ActionId."));
                }
                actionRelation.Action = actTest;
            }
            else if (actionRelation.Action == null)
            {
                return(HttpResponseHelper.NotFound("No Action found"));
            }

            _context.ActionRelations.Add(actionRelation);

            var error = await SaveChangesAsync();

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

            return(CreatedAtRoute("GetActionRelation", new { id = actionRelation.Id }, actionRelation));
        }
        public async Task <IActionResult> UpdateMatch([FromRoute] Guid id, [FromBody] Match matchForm)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var match = await _context.Matches.Where(m => m.Id.Equals(id)).FirstOrDefaultAsync();

            if (match == null)
            {
                return(HttpResponseHelper.NotFound("No such Match found."));
            }

            _context.Entry(match).State = EntityState.Modified;
            match.Title          = matchForm.Title;
            match.ExpirationDate = matchForm.ExpirationDate;
            match.IsFinished     = matchForm.IsFinished;
            match.IsDeleted      = matchForm.IsDeleted;

            var error = await SaveChangesAsync();

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

            return(Ok(match));
        }
        public async Task <IActionResult> GetMatchDetailed([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var match =
                await _context.Matches.Where(m => m.Id.Equals(id)).Include(m => m.Tournament).FirstOrDefaultAsync();

            if (match == null)
            {
                return(HttpResponseHelper.NotFound($"No Match found with Id {id}."));
            }

            match.Actors =
                await _context.MatchActors.Where(a => a.MatchId.Equals(id)).Include(a => a.Actor).ToListAsync();

            IList <Guid> matchActorIds = match.Actors.AsEnumerable().Select(a => a.Id).ToList();

            match.Rounds =
                await
                _context.MatchRounds.Where(r => matchActorIds.Contains(r.MatchActorId))
                .OrderBy(r => r.RoundNumber)
                .ToListAsync();

            return(Ok(match));
        }
        public async Task <IActionResult> AddPlayer([FromBody] UserForm register)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            if (string.IsNullOrWhiteSpace(register.Username) && string.IsNullOrWhiteSpace(register.Email))
            {
                return(HttpResponseHelper.BadRequest("Either Username or Email is required."));
            }

            if (string.IsNullOrWhiteSpace(register.Password))
            {
                return(HttpResponseHelper.BadRequest("Password is required."));
            }

            var player = new Player();

            if (!string.IsNullOrWhiteSpace(register.Username))
            {
                if (await Player.ExistsUsername(_context, register.Username))
                {
                    return(HttpResponseHelper.BadRequest("Player with this Username already exists."));
                }

                player.Username = register.Username;
            }

            if (!string.IsNullOrWhiteSpace(register.Email))
            {
                if (await Player.ExistsEmail(_context, register.Email))
                {
                    return(HttpResponseHelper.BadRequest("Player with this Email already exists."));
                }

                player.Email = register.Email;
            }

            player.Password = PasswordHelper.HashPassword(register.Password);

            _context.Players.Add(player);

            var error = await SaveChangesAsync();

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

            // Add or Update the CustomData
            error = await player.AddOrUpdateCustomData(_context, register.CustomData);

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

            return(CreatedAtRoute("GetPlayer", new { id = player.Id }, player));
        }
예제 #9
0
        public async Task <IActionResult> Unalliance([FromRoute] Guid allianceId)
        {
            if (session?.Player == null)
            {
                return(HttpResponseHelper.BadRequest("Error with your session."));
            }

            var actor = await _context.Actors.FindAsync(allianceId);

            if (actor == null)
            {
                return(HttpResponseHelper.NotFound("No such Actor found."));
            }

            var alliance =
                await _context.Alliances.Where(Alliance.IsAlliance(allianceId, session.Player.Id)).FirstOrDefaultAsync();

            if (alliance == null)
            {
                return(HttpResponseHelper.BadRequest("Alliance is not in list."));
            }

            _context.Alliances.Remove(alliance);

            var error = await SaveChangesAsync();

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

            return(Ok("Alliance Removed from the list."));
        }
예제 #10
0
        public async Task <IActionResult> GetGoalDetailed([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var goal = await _context.Goals.FindAsync(id);

            if (goal == null)
            {
                return(HttpResponseHelper.NotFound("No Goal found."));
            }
            goal.Concern = await _context.ConcernMatrix.FindAsync(goal.ConcernId);

            goal.RewardResource = await _context.RewardResourceMatrix.FindAsync(goal.RewardResourceId);

            goal.Feedback = await _context.GoalFeedback.FindAsync(goal.FeedbackId);

            goal.Roles = await _context.Roles.Where(r => r.GoalId.Equals(goal.Id)).ToListAsync();

            IList <Guid> activitiesIDs = goal.Roles.AsEnumerable().Select(r => r.ActivityId).ToList();

            goal.Activities =
                await _context.Activities.Where(a => activitiesIDs.Contains(a.Id)).OrderBy(a => a.Name).ToListAsync();

            goal.Rewards = await _context.Rewards.Where(r => r.GoalId.Equals(goal.Id)).ToListAsync();

            goal.Targets = await _context.Targets.Where(t => t.GoalId.Equals(goal.Id)).ToListAsync();

            goal.Actions = await _context.Actions.Where(a => a.GoalId.Equals(goal.Id)).ToListAsync();

            return(Ok(goal));
        }
예제 #11
0
        public async Task <IActionResult> DeleteGoal([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var goal = await _context.Goals.FindAsync(id);

            if (goal == null)
            {
                return(HttpResponseHelper.NotFound("No Goal found."));
            }

            goal.IsDeleted = true;

            var error = await SaveChangesAsync();

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

            return(Ok(goal));
        }
        public async Task <IActionResult> Logout([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var playerSession = await _context.Sessions.FindAsync(id);

            if (playerSession == null)
            {
                return(HttpResponseHelper.NotFound("No such Session found."));
            }

            playerSession.IsExpired = true;

            var error = await SaveChangesAsync();

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

            return(Ok(playerSession));
        }
        public async Task <IActionResult> DeleteAchievement([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var achievement = await _context.Achievements.FindAsync(id);

            if (achievement == null)
            {
                return(HttpResponseHelper.NotFound("No Achievement found."));
            }

            _context.Achievements.Remove(achievement);

            var error = await SaveChangesAsync();

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

            return(Ok(achievement));
        }
예제 #14
0
        public async Task <IActionResult> DisableGroup([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var group = await _context.Groups.FindAsync(id);

            if (group == null)
            {
                return(HttpResponseHelper.NotFound("No Group found."));
            }

            group.IsEnabled = false;

            var error = await SaveChangesAsync();

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

            return(Ok(group));
        }
예제 #15
0
        public async Task <IActionResult> AddItemType([FromBody] ItemType itemType)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var type = await _context.ItemTypes.Where(t => t.Name.Equals(itemType.Name)).FirstOrDefaultAsync();

            if (type != null)
            {
                return(HttpResponseHelper.BadRequest("ItemType '" + itemType.Name + "' already exists."));
            }

            _context.ItemTypes.Add(itemType);

            var error = await SaveChangesAsync();

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

            return(CreatedAtRoute("GetItemType", new { id = itemType.Id }, itemType));
        }
예제 #16
0
        public async Task <IActionResult> AddRole([FromBody] Role role)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var checkRole = await _context.Roles.Where(r => r.Name.Equals(role.Name)).FirstOrDefaultAsync();

            if (checkRole != null)
            {
                return(HttpResponseHelper.BadRequest("Role '" + checkRole.Name + "' already exists."));
            }

            _context.Roles.Add(role);

            var error = await SaveChangesAsync();

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

            return(CreatedAtRoute("GetRole", new { id = role.Id }, role));
        }
예제 #17
0
        public async Task <IActionResult> PutAction([FromRoute] Guid id, [FromBody] Action action)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var actionMatch = await _context.Actions.Where(g => g.Id.Equals(id)).FirstOrDefaultAsync();

            if (actionMatch == null)
            {
                return(HttpResponseHelper.NotFound("No such Action found."));
            }

            _context.Entry(actionMatch).State = EntityState.Modified;

            var error = await SaveChangesAsync();

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

            return(Ok(actionMatch));
        }
예제 #18
0
        public async Task <IActionResult> DeleteReward([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var reward = await _context.Rewards.FindAsync(id);

            if (reward == null)
            {
                return(HttpResponseHelper.NotFound("No Reward found."));
            }

            _context.Rewards.Remove(reward);

            var error = await SaveChangesAsync();

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

            return(Ok(reward));
        }
예제 #19
0
        public async Task <IActionResult> CreateGoal([FromBody] Goal goal)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            if (goal.ConcernId != Guid.Empty)
            {
                var concerntest = await _context.ConcernMatrix.FindAsync(goal.ConcernId);

                if (concerntest == null)
                {
                    return(HttpResponseHelper.NotFound("No Concern found for the passed ID"));
                }
            }
            else if (goal.Concern == null)
            {
                return(HttpResponseHelper.NotFound("No Concern found"));
            }

            if (goal.RewardResourceId != Guid.Empty)
            {
                var rrtest = await _context.RewardResourceMatrix.FindAsync(goal.RewardResourceId);

                if (rrtest == null)
                {
                    return(HttpResponseHelper.NotFound("No RewardResource found for the passed ID"));
                }
            }
            else if (goal.RewardResource == null)
            {
                return(HttpResponseHelper.NotFound("No RewardResource found"));
            }

            if (goal.FeedbackId != Guid.Empty)
            {
                var fbtest = await _context.GoalFeedback.FindAsync(goal.FeedbackId);

                if (fbtest == null)
                {
                    return(HttpResponseHelper.NotFound("No GoalFeedback found for the passed ID"));
                }
            }
            else if (goal.Feedback == null)
            {
                return(HttpResponseHelper.NotFound("No GoalFeedback found"));
            }

            _context.Goals.Add(goal);

            var error = await SaveChangesAsync();

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

            return(CreatedAtRoute("GetGoalDetailed", new { id = goal.Id }, goal));
        }
        public async Task <IActionResult> DeleteInventory([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var inventory = await _context.Inventory.FindAsync(id);

            if (inventory == null)
            {
                return(HttpResponseHelper.NotFound("No Inventory found."));
            }

            _context.Inventory.Remove(inventory);

            var error = await SaveChangesAsync();

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

            return(Ok(inventory));
        }
예제 #21
0
        public async Task <IActionResult> PutGoal([FromRoute] Guid id, [FromBody] Goal form)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var goal = await _context.Goals.Where(g => g.Id.Equals(id)).FirstOrDefaultAsync();

            if (goal == null)
            {
                return(HttpResponseHelper.NotFound("No such Goal found."));
            }

            _context.Entry(goal).State = EntityState.Modified;
            goal.Description           = form.Description;

            var error = await SaveChangesAsync();

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

            return(Ok(goal));
        }
예제 #22
0
        public async Task <IActionResult> GetActorGoal([FromRoute] Guid id)
        {
            var goal =
                await
                _context.ActorGoal.Where(g => g.GoalId.Equals(id))
                .Where(g => g.ActorId.Equals(session.Player.Id))
                .Include(g => g.Actor)
                .Include(g => g.Goal)
                .Include(g => g.ConcernOutcome)
                .Include(g => g.RewardResourceOutcome)
                .Include(g => g.Activity)
                .Include(g => g.Role)
                .FirstOrDefaultAsync();

            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            if (goal == null)
            {
                return(HttpResponseHelper.NotFound("No ActorGoal found."));
            }

            return(Ok(goal));
        }
예제 #23
0
        public async Task <IActionResult> UpdatePlayer([FromRoute] Guid id, [FromBody] UserForm form)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var player = await _context.Players.FindAsync(id);

            if (player == null)
            {
                return(HttpResponseHelper.NotFound("No such Player found."));
            }

            _context.Entry(player).State = EntityState.Modified;

            if (!string.IsNullOrWhiteSpace(form.Username) && player.Username != form.Username)
            {
                if (await Player.ExistsUsername(_context, form.Username))
                {
                    return(HttpResponseHelper.BadRequest("Player with this Username already exists."));
                }

                player.Username = form.Username;
            }

            if (!string.IsNullOrWhiteSpace(form.Email) && player.Email != form.Email)
            {
                if (await Player.ExistsEmail(_context, form.Email))
                {
                    return(HttpResponseHelper.BadRequest("Player with this Email already exists."));
                }

                player.Email = form.Email;
            }

            if (!string.IsNullOrWhiteSpace(form.Password))
            {
                player.Password = PasswordHelper.HashPassword(form.Password);
            }

            var error = await SaveChangesAsync();

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

            // Add or Update the CustomData
            error = await player.AddOrUpdateCustomData(_context, form.CustomData);

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

            return(Ok(player));
        }
예제 #24
0
        public async Task <IActionResult> UpdateMatchRoundScore([FromRoute] Guid id, [FromBody] MatchRoundForm form)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var match = await _context.Matches.Where(m => m.Id.Equals(id)).Include(m => m.Actors).FirstOrDefaultAsync();

            if (match == null)
            {
                return(HttpResponseHelper.NotFound("No such Match found."));
            }

            if (match.IsFinished)
            {
                return(HttpResponseHelper.BadRequest("This match is already finished."));
            }

            foreach (var actor in match.Actors.Where(actor => actor.ActorId.Equals(form.ActorId)))
            {
                var round =
                    await
                    _context.MatchRounds.Where(r => r.MatchActorId.Equals(actor.Id))
                    .Where(r => r.RoundNumber.Equals(form.RoundNumber))
                    .FirstOrDefaultAsync();

                if (round == null)
                {
                    return(HttpResponseHelper.NotFound($"No Round #{form.RoundNumber} found for Actor {form.ActorId}"));
                }

                _context.Entry(round).State = EntityState.Modified;
                round.Score     = form.Score;
                round.DateScore = DateTime.Now;

                var error = await SaveChangesAsync();

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

                return
                    (Ok(
                         new MatchRoundScoreResponse
                {
                    RoundNumber = round.RoundNumber,
                    ActorId = round.MatchActor.ActorId,
                    Actor = round.MatchActor.Actor,
                    Score = round.Score,
                    DateScore = round.DateScore
                }));
            }

            return(HttpResponseHelper.NotFound($"No Actor {form.ActorId} found for this Match."));
        }
        public async Task <IActionResult> Login([FromBody] UserForm login)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            if (string.IsNullOrWhiteSpace(login.Username) && string.IsNullOrWhiteSpace(login.Email))
            {
                return(HttpResponseHelper.BadRequest("Either Username or Email is required."));
            }

            if (string.IsNullOrWhiteSpace(login.Password))
            {
                return(HttpResponseHelper.BadRequest("Password is required."));
            }

            IQueryable <Player> query = _context.Players;

            if (!string.IsNullOrWhiteSpace(login.Username))
            {
                query = query.Where(a => a.Username.Equals(login.Username));
            }

            if (!string.IsNullOrWhiteSpace(login.Email))
            {
                query = query.Where(a => a.Email.Equals(login.Email));
            }

            var player = await query.FirstOrDefaultAsync();

            if (player == null)
            {
                return(HttpResponseHelper.NotFound("No such Player found."));
            }

            if (!PasswordHelper.ValidatePassword(login.Password, player.Password))
            {
                return(HttpResponseHelper.Unauthorized("Invalid Login Details."));
            }

            var playerSession = new Session {
                Player = player
            };

            _context.Sessions.Add(playerSession);

            var error = await SaveChangesAsync();

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

            return(CreatedAtRoute("GetSession", new { id = playerSession.Id }, playerSession));
        }
예제 #26
0
        public async Task <IActionResult> CreateGroup([FromBody] GroupFrom form)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            if (string.IsNullOrWhiteSpace(form.Name))
            {
                return(HttpResponseHelper.BadRequest("Group name is required."));
            }

            if (await Group.ExistsUsername(_context, form.Name))
            {
                return(HttpResponseHelper.BadRequest("Group with this name already exists."));
            }

            var group = new Group {
                Username = form.Name, Type = form.Type, AdminId = session.Player.Id
            };

            if (form.Players == null || form.Players.Count < 1)
            {
                return(HttpResponseHelper.BadRequest("Group requires minimum 1 Player."));
            }

            IList <Player> players = new List <Player>();

            foreach (var playerId in form.Players)
            {
                var player = await _context.Players.FindAsync(playerId);

                if (player == null)
                {
                    return(HttpResponseHelper.NotFound($"No Player with Id {playerId} exists."));
                }

                players.Add(player);
            }

            group.Players = players;

            _context.Groups.Add(group);

            var error = await SaveChangesAsync();

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

            return(CreatedAtRoute("GetGroupInfo", new { id = group.Id }, group));
        }
예제 #27
0
 public HttpResponseModel Set([FromBody] CharacterModel characterModel)
 {
     try
     {
         XmlAccess.SaveToFile(characterModel);
         return(HttpResponseHelper.OK("Character saved."));
     }
     catch (Exception ex)
     {
         return(HttpResponseHelper.BadRequest("Error: " + ex.Message));
     }
 }
예제 #28
0
        public async Task <IActionResult> AddActivityGoal([FromRoute] Guid id, [FromBody] ActivityGoalForm form)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var activity = await _context.Activities.Where(a => a.Id.Equals(id)).FirstOrDefaultAsync();

            if (activity == null)
            {
                return(HttpResponseHelper.NotFound("No such Activity found."));
            }

            var goal = new Goal
            {
                Description = form.Description,
                Concern     = new ConcernMatrix {
                    Coordinates = new Matrix {
                        X = 0, Y = 0
                    }
                },
                RewardResource = new RewardResourceMatrix {
                    Coordinates = new Matrix {
                        X = 0, Y = 0
                    }
                },
                Feedback = new GoalFeedback()
            };

            _context.Entry(activity).State = EntityState.Modified;

            if (activity.Goals?.Count > 0)
            {
                activity.Goals.Add(goal);
            }
            else
            {
                activity.Goals = new List <Goal> {
                    goal
                };
            }

            var error = await SaveChangesAsync();

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

            return(Ok(activity));
        }
        public async Task <IActionResult> GetAchievement([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var achievement = await _context.Achievements.FindAsync(id);

            if (achievement == null)
            {
                return(HttpResponseHelper.NotFound("No Achievement found."));
            }

            return(Ok(achievement));
        }
예제 #30
0
        public async Task <IActionResult> GetGoal([FromRoute] Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(HttpResponseHelper.BadRequest(ModelState));
            }

            var goal = await _context.Goals.FindAsync(id);

            if (goal == null)
            {
                return(HttpResponseHelper.NotFound("No Goal found."));
            }

            return(Ok(goal));
        }