Ejemplo n.º 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"));
            }
        }
Ejemplo n.º 2
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."));
            }
        }