public async Task <StudentBasket> UpdateBasketAsync(StudentBasket basket)
        {
            var created = await _database.StringSetAsync(basket.StudentId, JsonConvert.SerializeObject(basket));

            if (!created)
            {
                _logger.LogInformation("Problem occured persisting the item.");
                return(null);
            }

            _logger.LogInformation("Basket item persisted succesfully.");

            return(await GetBasketAsync(basket.StudentId));
        }
Example #2
0
        private StudentBasket MapToStudentBasket(StudentBasketRequest studentBasketRequest)
        {
            var response = new StudentBasket
            {
                StudentId = studentBasketRequest.Studentid
            };

            studentBasketRequest.Items.ToList().ForEach(item => response.Items.Add(new BasketItem
            {
                Id                  = item.Id,
                OldSlotAmount       = (decimal)item.Oldslotamount,
                PictureUrl          = item.Pictureurl,
                ScholarshipItemId   = item.Scholarshipitemid,
                ScholarshipItemName = item.ScholarshipItemname,
                Slots               = item.Slots,
                SlotAmount          = (decimal)item.Slotamount
            }));

            return(response);
        }
Example #3
0
        private StudentBasketResponse MapToStudentBasketResponse(StudentBasket studentBasket)
        {
            var response = new StudentBasketResponse
            {
                Studentid = studentBasket.StudentId
            };

            studentBasket.Items.ForEach(item => response.Items.Add(new BasketItemResponse
            {
                Id                  = item.Id,
                Oldslotamount       = (double)item.OldSlotAmount,
                Pictureurl          = item.PictureUrl,
                Scholarshipitemid   = item.ScholarshipItemId,
                ScholarshipItemname = item.ScholarshipItemName,
                Slots               = item.Slots,
                Slotamount          = (double)item.SlotAmount
            }));

            return(response);
        }
Example #4
0
 public async Task <ActionResult <StudentBasket> > UpdateBasketAsync([FromBody] StudentBasket value)
 {
     return(Ok(await _repository.UpdateBasketAsync(value)));
 }
        private async Task UpdateAmountInBasketItems(int scholarshipItemId, decimal newAmount, decimal oldAmount, StudentBasket basket)
        {
            var itemsToUpdate = basket?.Items?.Where(x => x.ScholarshipItemId == scholarshipItemId).ToList();

            if (itemsToUpdate != null)
            {
                _logger.LogInformation("----- ScholarshipItemAmountChangedIntegrationEventHandler - Updating items in basket for user: {Studentd} ({@Items})", basket.StudentId, itemsToUpdate);

                foreach (var item in itemsToUpdate)
                {
                    if (item.SlotAmount == oldAmount)
                    {
                        var originalAmount = item.SlotAmount;
                        item.SlotAmount    = newAmount;
                        item.OldSlotAmount = originalAmount;
                    }
                }
                await _repository.UpdateBasketAsync(basket);
            }
        }