/// <summary> /// Gets a customer event user by id /// </summary> /// <returns>CameleoCustomerEventViewModel</returns> public CameleoCustomerEventViewModel GetCustomerEventViewModel(int customerEventId) { var tmpCustomerEvent = GetCustomerEventById(customerEventId); if (tmpCustomerEvent == null) { return(null); } else { CameleoCustomerEventViewModel customerEventViewModel = new CameleoCustomerEventViewModel(tmpCustomerEvent, _customerService.GetCustomerById(tmpCustomerEvent.CustomerId).Username, _localizationService.GetResource(AcceptedStatusStrings.LocalizedStringValues[tmpCustomerEvent.AcceptedStatus])); var tmpEventUser = _eventUserService.GetEventUserById(tmpCustomerEvent.EventUserId); var tmpEvent = _eventService.GetEventById(tmpEventUser.EventId); customerEventViewModel.CameleoEventUser = new CameleoEventUserViewModel(tmpEventUser, _eventUserService.GetEventUsersCount(_eventUserService.GetEventUserById(tmpCustomerEvent.EventUserId)), _eventUserService.GetAcceptedEventUsersCount(_eventUserService.GetEventUserById(tmpCustomerEvent.EventUserId))); customerEventViewModel.CameleoEvent = new CameleoEventViewModel(tmpEvent, _eventService.GetAllGroupsForEvent(tmpEventUser.EventId), _localizationService.GetResource(CameleoEventStatusStrings.LocalizedStringValues[tmpEvent.Status])); return(customerEventViewModel); } }
public ActionResult AddShoppingCartItem(int customerEventId) { var tmpCustomerEvent = _customerEventService.GetCustomerEventById(customerEventId); if (tmpCustomerEvent == null) { //Customer event not found throw new ArgumentException(_localizationService.GetResource("Plugins.Cameleo.CameleoCustomerEvents.Delete.NotFound")); } var tmpEvenUser = _eventUserService.GetEventUserById(tmpCustomerEvent.EventUserId); if (tmpEvenUser == null) { //Customer event not found throw new ArgumentException(_localizationService.GetResource("Plugins.Cameleo.CameleoCustomerEvents.EventUser.NotFound")); } var tmpEvent = _eventService.GetEventById(tmpEvenUser.EventId); if (tmpEvent == null) { //Customer event not found throw new ArgumentException(_localizationService.GetResource("Plugins.Cameleo.CameleoCustomerEvents.Event.NotFound")); } var tmpCustomer = _customerService.GetCustomerById(tmpCustomerEvent.CustomerId); if (tmpCustomer == null) { //Customer not found throw new ArgumentException(_localizationService.GetResource("Plugins.Cameleo.CameleoCustomerEvents.AddShoppingCartItem.NotFound")); } //Add product to cart var product = _productService.GetProductBySku(CameleoEventProducts.PRODUCT_VIDEO_PROJECT); if (product == null) { //Product not found throw new ArgumentException(_localizationService.GetResource("plugins.cameleo.cameleocustomerevents.videoprojectproduct.notfound")); } //Add to cart decimal configuredPrice = tmpEvent.ParticipationFee.HasValue ? tmpEvent.ParticipationFee.Value : product.Price; var warnings = _shoppingCartService.AddToCart(tmpCustomer, product, ShoppingCartType.ShoppingCart, _storeContext.CurrentStore.Id, string.Empty, configuredPrice, 1, true); if (warnings.Count == 0) { //Get last added cart item var cart = tmpCustomer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .Where(sci => sci.StoreId == _storeContext.CurrentStore.Id) .OrderByDescending(sci => sci.CreatedOnUtc) .ToList(); if (cart.Count > 0) { var tmpCartItem = cart[0]; //Keep customer event id _genericAttributeService.SaveAttribute <int>(tmpCartItem, CameleoGenericAttributeNames.CameleoCustomerEvent + tmpCustomerEvent.Id, tmpCustomerEvent.Id, _storeContext.CurrentStore.Id); } } else { //Error adding to cart _logger.Error(_localizationService.GetResource("plugins.cameleo.cameleocustomerevents.videoprojectproduct.adderror") + " " + warnings.ToString()); } // Refresh view return(new NullJsonResult()); }