public async Task <CartViewModel> Change(CartItemChangeViewModel item) { try { var customer = await _currentContext.GetCurrentCustomer(); CartViewModel model = new CartViewModel(await InitAjax()); RCart cart = await _cartService.GetFromCache(_currentContext.ClientId, EnumDefine.CartStatusEnum.New); if (cart == null) { //int shardId= _commonService.get var command = item.ToCommand(1, _currentContext.LanguageId, customer.Id); long systemIdentity = await _commonService.GetNextId(typeof(Cart)); CartAddCommand cartAddCommand = new CartAddCommand(SystemDefine.DefaultVersion) { LanguageId = _currentContext.LanguageId, Code = Common.Common.GenerateCodeFromId(systemIdentity), StoreId = ConfigSettingEnum.StoreId.GetConfig(), ClientId = _currentContext.ClientId, CreatedUid = customer.Id ?? string.Empty, CartItem = command, CartItemDetail = new CartItemDetailAddCommand(SystemDefine.DefaultVersion) { ProductId = command.ProductId, Name = "Name", } }; await _cartService.Add(cartAddCommand); } else { //if (cart.Version != item.Version) //{ // model.AddMessage(ResourceKey.Cart_IsChanged); // return model; //} CartItemChangeCommand command = item.ToCommand(1, _currentContext.LanguageId, customer.Id, cart); await _cartService.Change(command); } cart = await _cartService.GetFromCache(_currentContext.ClientId, EnumDefine.CartStatusEnum.New); model.CartItems = cart.CartItemFulls?.Select(p => p.ToModel()).ToArray(); return(model); } catch (Exception e) { _logger.LogError(e, e.Message); throw e; } }
public Cart(CartAddCommand command, int shardId, int version) : this(version) { Id = Common.Common.GenerateGuid(); Code = command.Code; CartItems = new List <CartItem>(); CartItemDetails = new ConcurrentDictionary <string, CartItemDetail>(); ClientId = command.ClientId; CreatedDateUtc = command.CreatedDateUtc; CreatedUid = command.CreatedUid; LanguageId = command.LanguageId; StoreId = command.StoreId; Status = EnumDefine.CartStatusEnum.New; ShardId = shardId; }
public async Task <CommandResult> Add(CartAddCommand command) { CommandResult commandResult = await _commandService.SendAndReceiveResult <CommandResult>(command); return(commandResult); }