Пример #1
0
        public async Task <bool> MakeDonationAsync(GiftCardCreateViewModel card)
        {
            if (string.IsNullOrWhiteSpace(BearerToken))
            {
                throw new UnauthorizedAccessException("Bearer token not initialized. Aborting.");
            }

            using (var client = new HttpClient())
            {
                // Build API URL.
                var url = $"{_apiUrl}/api/Card";

                // Construct the request.
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", BearerToken);

                // Create the JSON version of the note object. JSON is a string we'll send to the server.
                var json = JsonConvert.SerializeObject(card);

                // Make the call and get the result.
                var result = await client.PostAsync(url, new StringContent(json, Encoding.UTF8, "application/json")); // we have to specify we're sending JSON

                // If the call failed, return an empty list.
                return(result.IsSuccessStatusCode);
            }
        }
Пример #2
0
        public bool CreateGiftCard(GiftCardCreateViewModel model)
        {
            using (var context = new ApplicationDbContext())
            {
                var company = context
                              .Company
                              .Where(e => e.CompanyName == model.CompanyName)
                              .FirstOrDefault();

                var companyId = company.CompanyId;

                var entity =
                    new GiftCard()
                {
                    OwnerId     = _userId,
                    Amount      = model.Amount,
                    CardNumber  = model.CardNumber,
                    DonationUtc = DateTime.Now,
                    CompanyId   = companyId,

                    //  Optional
                    ExpirationDate = model.ExpirationDate,
                    AccessNumber   = model.AccessNumber
                };

                company.CompanyAmount = company.CompanyAmount + entity.Amount;

                context.GiftCard.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
Пример #3
0
        //  POST /api/Card
        public IHttpActionResult Post(GiftCardCreateViewModel card)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            GiftCardService cardService = CreateCardService();

            cardService.CreateGiftCard(card);

            return(Ok());
        }
Пример #4
0
 public Task <bool> MakeDonationAsync(GiftCardCreateViewModel card)
 {
     throw new NotImplementedException();
 }