Exemple #1
0
        public IActionResult DeclineTask(int id)
        {
            var task = _context.Tasks.Find(id);

            if (task == null)
            {
                return(BadRequest());
            }

            if (!User.IsAllowed(_context, id))
            {
                return(Forbid());
            }

            var participant = User.GetParticipant(_context);

            _context.Execute(ParticipantEventTask.DeleteSql(participant, task));

            task.Tags = _context.TaskTags.Where(new { EventTask_Id = task.Id }).ToList();

            task.Tags.ForEach((t) => {
                t.Task  = task;
                t.Value = null;
                _context.TaskTags.Update(t);
            });

            task.Attributes   = _context.TaskAttributes.Where(new { EventTask_Id = task.Id }).ToList();
            task.Participants = _context.Participants.Query(ParticipantEventTask.SelectParticipantsSql(), new { task.Id }).ToList();

            return(Ok(new { Task = task, Participant = participant }));
        }
Exemple #2
0
        public IActionResult AcceptTask(int id)
        {
            var task = _context.Tasks.Find(id);

            if (task == null)
            {
                return(BadRequest("Invalid parameter"));
            }

            if (!User.IsAllowed(_context, id))
            {
                return(Forbid());
            }

            try
            {
                var participant = User.GetParticipant(_context);

                task.Participants = _context.Participants.Query(ParticipantEventTask.SelectParticipantsSql(), new { task.Id }).ToList();
                if (task.MaxParticipants <= task.Participants.Count())
                {
                    return(BadRequest("Someone else has already volunteered for this task while you were thinking.  Better luck next time!"));
                }

                _context.Execute(ParticipantEventTask.InsertSql(participant, task));

                task.Tags         = _context.TaskTags.Where(new { EventTask_Id = task.Id }).ToList();
                task.Attributes   = _context.TaskAttributes.Where(new { EventTask_Id = task.Id }).ToList();
                task.Participants = _context.Participants.Query(ParticipantEventTask.SelectParticipantsSql(), new { task.Id }).ToList();

                return(Ok(new { Task = task, Participant = participant }));
            }
            catch (SqlException e)
            {
                if (e.Number == 2627)
                {
                    return(BadRequest("You have already volunteered for this task."));
                }
                return(StatusCode(500, "An error has occured while attempting to save your change.  We apologize for the invonvience."));
            }
        }