示例#1
0
        public async Task <IActionResult> AddPhone(PhoneModel newPhone)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Phones"));
            }

            if (string.IsNullOrWhiteSpace(newPhone.Brand) || string.IsNullOrWhiteSpace(newPhone.Model))
            {
                return(RedirectToAction("Phones"));
            }

            var successful = await _phoneService.AddPhoneAsync(newPhone);

            if (!successful)
            {
                return(BadRequest("Could not add phone."));
            }

            return(RedirectToAction("Phones"));
        }
        public async Task <HttpResponseMessage> AssignOfferToTheSubscriber([FromUri] int subscriberId, [FromUri] int offerId)
        {
            try
            {
                Task <SubscriberBl> chosenSubscriber = _combiningUserOfferService.GetSubscriberAsync(subscriberId);
                Task <OfferBl>      chosenOffer      = _combiningUserOfferService.GetOfferAsync(offerId);

                await Task.WhenAll(chosenSubscriber, chosenOffer);

                var generatedNumber = _phoneService.GeneratePhoneNumber();

                var newPhone = _phoneDataCapture.Capture(chosenOffer.Result, generatedNumber);

                var phoneId = await _phoneService.AddPhoneAsync(subscriberId, offerId, newPhone);

                return(Request.CreateResponse(HttpStatusCode.OK, phoneId));
            }
            catch (Exception e)
            {
                var message = $"Assigning offer to the subscriber failed. {e.Message}";
                return(Request.CreateResponse(HttpStatusCode.BadRequest, message));
            }
        }
示例#3
0
 public async Task AddGeneratedPhoneAsync(int indexOfSubscriber, int indexOfOffer, PhoneBl phoneBl)
 {
     await _phoneService.AddPhoneAsync(indexOfSubscriber, indexOfOffer, phoneBl);
 }