Ejemplo n.º 1
0
        public async Task <ActionResult <CustomerBasket> > SetBasketAsync(CustomerBasketDto basket)
        {
            var basketZ       = _mapper.Map <CustomerBasketDto, CustomerBasket>(basket);
            var createdBasket = await _basketRepository.UpdateBasketAsync(basketZ);

            return(Ok(createdBasket));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basket)
        {
            var customerBasket = _mapper.Map <CustomerBasketDto, CustomerBasket>(basket); // automatically map attribute of class (same name)
            var updateBasket   = await _basketRepository.UpdateBasketAsync(customerBasket);

            return(Ok(updateBasket));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <CustomerBasket> > CreateOrUpdateBasket(CustomerBasketDto customerBasket)
        {
            var basket     = _mapper.Map <CustomerBasketDto, CustomerBasket>(customerBasket);
            var basketdata = await _basketRepository.UpdateBasketAsync(basket);

            return(Ok(basketdata));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basket)
        {
            var customerBasket = mapper.Map <CustomerBasket>(basket);
            var updatedBasket  = await basketRepository.UpdateBasketAsync(customerBasket);

            return(Ok(updatedBasket));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basket)
        {
            var CustomerBasket = _mapper.Map <CustomerBasketDto, CustomerBasket>(basket);
            var UpdateBasket   = await _basketRepository.UpdateBasketAsync(CustomerBasket);

            return(Ok(UpdateBasket));
        }
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basket)
        {
            var basketForId = await _context.CustomerBaskets.FirstOrDefaultAsync(x => x.Guid.ToString() == basket.Guid);

            if (basketForId != null)
            {
                await _context.Database.ExecuteSqlRawAsync("DELETE FROM [BasketItems] WHERE [BasketItems].CustomerBasketId = " + basketForId.Id);
            }

            var basketFromRepo = await _context.CustomerBaskets.Include(x => x.Items).FirstOrDefaultAsync(x => x.Guid.ToString() == basket.Guid.ToString());

            if (basketFromRepo == null)
            {
                return(BadRequest("No basket in db"));
            }

            var itemsToAdd = _mapper.Map <List <BasketItem> >(basket.Items);

            foreach (var item in itemsToAdd)
            {
                basketFromRepo.Items.Add(item);
            }

            _context.Update(basketFromRepo);

            await _context.SaveChangesAsync();

            return(Ok(basketFromRepo));
        }
Ejemplo n.º 7
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto customerBasketDto)
        {
            var basket        = _mapper.Map <CustomerBasket> (customerBasketDto);
            var updatedBasket = await _basketRepo.SetBasketAsync(basket);

            return(Ok(basket));
        }
        public async Task <ActionResult <CustomerBasketDto> > UpdateBasket(CustomerBasketDto basket)
        {
            var customerBasket = _mapper.Map <CustomerBasketDto, CustomerBasket> (basket);
            var updatedBasket  = await _basketManager.UpdateBasketAsync(customerBasket);

            return(Ok(updatedBasket));
        }
Ejemplo n.º 9
0
        public async Task <ActionResult <CustomerBasket> > CreateOrUpdateBasketAsync(CustomerBasketDto basket)
        {
            var customerBasket = _mapper.Map <CustomerBasketDto, CustomerBasket>(basket);
            var result         = await _repo.CreateOrUpdateBasketAsync(customerBasket);

            return(Ok(result));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult <CustomerBasket> > CreateOrUpdateBasket(CustomerBasketDto basket)
        {
            var customerBasket     = _mapper.Map <CustomerBasketDto, CustomerBasket>(basket);
            var newOrUpdatedBasket = await _basketRepository.CreateOrUpdateBasketAsync(customerBasket);

            return(Ok(newOrUpdatedBasket));
        }
Ejemplo n.º 11
0
        public async Task <ActionResult <CustomerBasketDto> > UpdateBasketAsync([FromBody] CustomerBasketDto basketDto)
        {
            CustomerBasket basket = Map <CustomerBasket>(basketDto);

            CustomerBasket updated = await _basketRepository.UpdateBasketAsync(basket);

            return(Map <CustomerBasketDto>(updated));
        }
Ejemplo n.º 12
0
        public async Task <CustomerBasketDto> GetCustomerBasket([FromQuery] string basketId)
        {
            CustomerBasket customerBasket = await _basketRepository.GetBasketAsync(basketId);

            CustomerBasketDto customerBasketDto = _mapper.Map <CustomerBasket, CustomerBasketDto>(customerBasket);

            return(customerBasketDto);
        }
Ejemplo n.º 13
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basket)
        {
            var customerBasket = _autoMapper.Map <CustomerBasketDto, CustomerBasket>(basket);
            var update         = await
                                 _basketRepository.UpdateOrCreateBasketAsync(customerBasket);

            return(Ok(update));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> UpdateBasket(CustomerBasketDto basketDto)
        {
            var customerBasket = _mapper.Map <CustomerBasketDto, CustomerBasket>(basketDto);

            var updated = await _basketRepo.UpdateBasketAsync(customerBasket);

            return(Ok(customerBasket));
        }
Ejemplo n.º 15
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basket)
        {
            // or save this in variable and pass in method:
            // var customerBasket = _mapper.Map<CustomerBasketDto, CustomerBasket>(basket);
            var updatedBasket = await _basketRepository.UpdateBasketAsync(
                _mapper.Map <CustomerBasketDto, CustomerBasket>(basket));

            return(Ok(updatedBasket));
        }
Ejemplo n.º 16
0
        public async Task <ActionResult <CustomerBasketDto> > SetCustomerBasket(CustomerBasketDto basket)
        {
            CustomerBasket customerBasket = _mapper.Map <CustomerBasketDto, CustomerBasket>(basket);

            customerBasket = await _basketRepository.AddOrUpdateBasketAsync(customerBasket);

            CustomerBasketDto customerBasketDto = _mapper.Map <CustomerBasket, CustomerBasketDto>(customerBasket);

            return(Ok(customerBasketDto));
        }
Ejemplo n.º 17
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basket)
        {
            // dont need to do anything with basketItem as automapper will recognise basketItems comming
            // from the CustomerBasketDto, these need to be mapped too so will map them
            var customerBasket = _mapper.Map <CustomerBasketDto, CustomerBasket>(basket);

            var updatedBasket = await _basketRepository.UpdateBasketAsync(customerBasket);

            return(Ok(updatedBasket));
        }
Ejemplo n.º 18
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basket)
        {
            if (basket.Id == null || basket.Id == "undefined")
            {
                var newGuidValue = Guid.NewGuid();
                basket.Id = newGuidValue.ToString();
            }
            var customerBasket = _mapper.Map <CustomerBasketDto, CustomerBasket>(basket);
            var updateBasket   = await _basketRepository.UpdateBasketAsync(customerBasket);

            return(Ok(updateBasket));
        }
Ejemplo n.º 19
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basket)
        {
            //identify the received data from the client angular side as CustomerBasketDto, not the original model CustomerBasket !
            //indded, the CustomerBasketDto and CustomerBasket have the same properties, but in CustomerBasketDto we did validations using data annotations !

            //after the validation has been done, transfer back from Dto to the original model:
            var CustomerBasket = _mapper.Map <CustomerBasketDto, CustomerBasket>(basket);

            //then update:
            var updatedBasket = await _basketRepository.UpdateBasketAsync(CustomerBasket);

            return(Ok(updatedBasket));
        }
Ejemplo n.º 20
0
        public async Task <ActionResult <CustomerBasket> > UpdateBasket(CustomerBasketDto basketDto)
        {
            var basketItem = new BasketItem()
            {
                Id = basketDto.Items[0].Id, Type = basketDto.Items[0].Type, Brand = basketDto.Items[0].Brand, ProductName = basketDto.Items[0].ProductName, Price = basketDto.Items[0].Price, PictureUrl = basketDto.Items[0].PictureUrl, Quantity = basketDto.Items[0].Quantity
            };
            var item = new List <BasketItem>();

            item.Add(basketItem);
            var basket = new CustomerBasket()
            {
                Id = basketDto.Id, Items = item
            };                                                             //_mapper.Map<CustomerBasket>(basketDto);
            var updatedBasket = await _basketRepository.UpdateBasketAsync(basket);

            return(Ok(updatedBasket));
        }