public HttpResponseMessage GetAll()
        {
            ItemsResponse <Sponsor> responseBody = new ItemsResponse <Sponsor>();

            responseBody.Items = _service.Get();
            HttpStatusCode statusCode = HttpStatusCode.OK;

            if (responseBody.Items == null)
            {
                statusCode = HttpStatusCode.NotFound;
            }
            return(Request.CreateResponse(statusCode, responseBody));
        }
        public IHttpActionResult GetAvailablePaymentMethods([FromUri] UserPaymentModel requestModel)
        {
            if (requestModel == null || !ModelState.IsValid)
            {
                return(Json(new { Success = false, Message = "Invalid data supplied" }));
            }
            ;
            //first check if the customer has an address, otherwise first address form will be shown

            var currentUser = ApplicationContext.Current.CurrentUser;

            var battleId     = requestModel.BattleId;
            var battleType   = requestModel.BattleType;
            var purchaseType = requestModel.PurchaseType;

            //TODO: Remove comment when picture battles are ready
            var battle = _videoBattleService.Get(battleId); // Model.BattleType == BattleType.Video ? _videoBattleService.GetById(Model.BattleId) : null;

            var responseModel = new UserPaymentPublicModel {
                IsAmountVariable     = purchaseType == PurchaseType.SponsorPass || battle.CanVoterIncreaseVotingCharge,
                MinimumPaymentAmount = purchaseType == PurchaseType.SponsorPass ? battle.MinimumSponsorshipAmount : battle.MinimumVotingCharge,
                PurchaseType         = requestModel.PurchaseType
            };

            //if purchase type is sponsor and customer is already a sponsor, he should not have a minimum amount criteria
            if (purchaseType == PurchaseType.SponsorPass)
            {
                var alreadySponsor = _sponsorService.Get(x => x.BattleId == battleId && x.BattleType == battleType, null).Any();
                if (alreadySponsor)
                {
                    responseModel.MinimumPaymentAmount = 1;
                }
            }

            //get available credits
            responseModel.AvailableCredits = _creditService.GetAvailableCreditsCount(currentUser.Id, null);

            //set the usable credits now
            responseModel.UsableCredits = _creditService.GetUsableCreditsCount(currentUser.Id);

            //let's get the payment methods for the logged in user
            var paymentMethods = _paymentMethodService.GetCustomerPaymentMethods(currentUser.Id);

            foreach (var pm in paymentMethods)
            {
                responseModel.UserPaymentMethods.Add(new System.Web.Mvc.SelectListItem()
                {
                    Text  = pm.NameOnCard + " (" + pm.CardNumberMasked + ")",
                    Value = pm.Id.ToString()
                });
            }
            if (battle.VideoBattleStatus == BattleStatus.Complete)
            {
                return(Json(new { Success = false, Message = "Battle completed" }));
            }
            //battle should not be complete before payment form can be opened
            return(Json(new { Success = true, AvailablePaymentMethods = responseModel }));
        }
Beispiel #3
0
        public void Update_Test()
        {
            Sponsor sponsor = new Sponsor();

            sponsor.Address     = new Address();
            sponsor.SponsorType = new SponsorType();
            sponsor             = _sponsorService.Get(1);

            //Arrange
            SponsorUpdateRequest sponsorUpdate = new SponsorUpdateRequest
            {
                Id                   = sponsor.Id,
                Name                 = "Instagram",
                CompanyUrl           = "https://yandex.com/",
                AddressId            = sponsor.Address.Id + 1,
                PhoneNumber          = "9184309283",
                ContactPerson        = "Kevin Systrom",
                PrimarySponsorTypeId = sponsor.SponsorType.Id + 1
            };

            //Act
            _sponsorService.Update(sponsorUpdate);
            Sponsor anotherSponsor = new Sponsor();

            anotherSponsor.Address     = new Address();
            anotherSponsor.SponsorType = new SponsorType();
            anotherSponsor             = _sponsorService.Get(1);

            //Assert
            Assert.IsTrue(sponsor.Id == anotherSponsor.Id, "Id don't match");
            Assert.IsFalse(sponsor.Name == anotherSponsor.Name, "Name hasn't changed");
            Assert.IsFalse(sponsor.CompanyUrl == anotherSponsor.CompanyUrl, "CompanyUrl hasn't changed");
            Assert.IsFalse(sponsor.Address.Id == anotherSponsor.Address.Id, "Address hasn't changed");
            Assert.IsFalse(sponsor.PhoneNumber == anotherSponsor.PhoneNumber, "PhoneNumber hasn't changed");
            Assert.IsFalse(sponsor.ContactPerson == anotherSponsor.ContactPerson, "ContactPerson hasn't changed");
            Assert.IsFalse(sponsor.SponsorType.Id == anotherSponsor.SponsorType.Id, "SponsorType Id hasn't changed");
        }