public HttpResponseMessage AddBook(dynamic body) { // dato un utente, va a reperire il basket dell'utente, se esiste // aggiorna il basket int bookId = body.bookId; var basket = _basketRepository .GetAll() .FirstOrDefault(x => x.Username == User.Identity.Name); if (basket == null) { basket = new Basket { Username = User.Identity.Name }; } var book = _bookRepository.Get(bookId); _basketRepository.AddBook(basket, book); _basketRepository.SaveOrUpdate(basket); return Request.CreateResponse(HttpStatusCode.OK); }
public void SaveOrUpdate(Basket basket) { if (!_baskets.Contains(basket)) { _baskets.Add(basket); } Save(basket); }
public void AddBook(Basket basket, Book book) { if (basket.Books == null) { basket.Books = new List<Book>(); } basket.Books.Add(book); }
public void Save(Basket basket) { var index = _baskets.FindIndex(x => x.Id == basket.Id); _baskets.RemoveAt(index); _baskets.Insert(index, basket); }
public void Add(Basket basket) { _baskets.Add(basket); }