Пример #1
0
        public ActionResult AddLeapee(CreateLeapRequest createRequest)
        {
            var repository   = new LeapRepository();
            var randomLeaper = repository.GetRandomLeaper();
            int @leaperId    = randomLeaper.Id;
            int @leapeeId    = repository.GetRandomLeapee().Id;
            int @eventId     = 0;
            var eventAssociatedWithLeapee = repository.GetEventAssociatedWithLeapee(leapeeId);

            if (eventAssociatedWithLeapee != null)
            {
                eventId = eventAssociatedWithLeapee.Id;
            }
            else
            {
                return(NotFound("Event already exist in another leap for that leapee. Please try again"));
            }

            if (randomLeaper.BudgetAmount > createRequest.Cost)
            {
                var newLeap = repository.AddLeapAndUpdateBudget(leaperId, leapeeId, eventId, createRequest.Cost);
                return(Created($"api/leapees/{newLeap.Id}", newLeap));
            }
            else
            {
                return(BadRequest("Sorry, you can not leap because you don't have enough budget. Better luck next time"));
            }
        }
Пример #2
0
        public ActionResult AddLeap(CreateLeapRequest createRequest)
        {
            var newLeap = _leapRepository.AddLeap(
                createRequest.LeaperId);

            return(Created($"/api/leap/{newLeap.Id}", newLeap));
        }
Пример #3
0
        public ActionResult <int> AddLeap(CreateLeapRequest createRequest)
        {
            //if (!_validator.Validate(createRequest))

            // return BadRequest(new { error = "users must have a username" });

            var newLeap = _leapRepository.AddLeapeeToLeaper(createRequest.LeapeeId, createRequest.LeaperId, createRequest.EventId, createRequest.Cost);

            return(Created($"api/leaper", newLeap));
        }
Пример #4
0
        public ActionResult AddLeapee(CreateLeapRequest createRequest)
        {
            var repository   = new LeapRepository();
            var randomLeaper = repository.GetRandomLeaper();
            int @leaperId    = randomLeaper.Id;
            int @leapeeId    = repository.GetRandomLeapee().Id;
            int @eventId     = 0;

            if (randomLeaper.BudgetAmount > createRequest.Cost)
            {
                var newLeap = repository.RetrieveUpdatedBudgetFromLeap(leaperId, leapeeId, eventId, createRequest.Cost);
                return(Created($"api/leap/{newLeap.Id}", newLeap));
            }
            else
            {
                return(BadRequest("Sorry, you don't have enough money to leap."));
            }
        }