public JsonResult GetBasketPositions(Guid?id, int?page, int?start, int?limit) { try { Order basket = GetBasket(); var positions = unitOfWork.PositionRepository().Get(d => d.OrderId == basket.OrderId); List <BasketPosition> basketPositions = new List <BasketPosition>(); foreach (Position position in positions) { BasketPosition basketPosition = new BasketPosition(); basketPosition.PositionId = position.PositionId; basketPosition.Count = position.ItemsCount; Item item = unitOfWork.ItemRepository().Get(d => d.ItemId == position.ItemId).First(); basketPosition.Name = item.Name; basketPosition.Code = item.Code; basketPosition.Price = item.Price; basketPositions.Add(basketPosition); } unitOfWork.Save(); return(this.Json(new { success = true, data = basketPositions })); } catch (Exception e) { return(this.Json(new { success = false, error = e.Message })); } }
public void AddToBasket(int productID) { var basket = DownloadBasket(); var basketPosition = basket.Find(a => a.Product.ProductID == productID); if (basketPosition != null) { basketPosition.Quantity++; } else { var productToAdd = db.Products.Where(a => a.ProductID == productID).SingleOrDefault(); if (productToAdd != null) { var newBasketPosition = new BasketPosition() { Product = productToAdd, Quantity = 1, Value = productToAdd.Price, }; basket.Add(newBasketPosition); } } session.Set(Consts.BasketSessionKey, basket); }
public void AddToBasket(int equipmentId) { var basket = GetBasket(); var basketPosition = basket.Find(b => b.Equipment.EquipmentId == equipmentId); if (basketPosition != null) { basketPosition.Quantity++; } else { var equipmentToAdd = db.AllEquipment.Where(c => c.EquipmentId == equipmentId).SingleOrDefault(); if (equipmentToAdd != null) { var newBasketPosition = new BasketPosition() { Equipment = equipmentToAdd, Quantity = 1, Value = equipmentToAdd.EquipmentPrice }; basket.Add(newBasketPosition); } } session.Set(Const.BasketSessionKey, basket); }
public async Task Execute(BasketPositionCreationModel commandData) { BasketPosition basketPosition = commandData.ToBasketPosition(); if (await this.basketRepository.Exists(basketPosition)) { throw new InvalidDataException("This basket position has already added"); } ProductModel product = await this.productRepository.Get(basketPosition.ProductId); basketPosition.ProductName = product.Name; basketPosition.ProductDescription = product.Description; await this.basketRepository.Add(basketPosition); }
public async Task <bool> Exists(BasketPosition basketPosition) { return(await this.dbContext.BasketPositions.AnyAsync(position => position.CustomerId == basketPosition.CustomerId && position.ProductId == basketPosition.ProductId)); }
public async Task Add(BasketPosition basketPosition) { await this.dbContext.BasketPositions.AddAsync(basketPosition); await this.dbContext.SaveChangesAsync(); }