示例#1
0
        public ActionResult CustomerEventUpdate(CameleoCustomerEventViewModel model)
        {
            var tmpCustomerEvent = _customerEventService.GetCustomerEventById(model.Id);

            if (tmpCustomerEvent == null)
            {
                //Customer event not found
                throw new ArgumentException(_localizationService.GetResource("Plugins.Cameleo.CameleoCustomerEvents.Delete.NotFound"));
            }

            //Update Customer event
            if (model.AcceptedStatus == (int)AcceptedStatus.ToBeCompleted || model.AcceptedStatus == (int)AcceptedStatus.Refused)
            {
                tmpCustomerEvent.Accepted = false;
            }
            else
            {
                tmpCustomerEvent.Accepted = true;
            }
            tmpCustomerEvent.AcceptedStatus   = model.AcceptedStatus;
            tmpCustomerEvent.AcceptedImageUse = model.AcceptedImageUse;
            tmpCustomerEvent.Paid             = model.Paid;
            _customerEventService.UpdateCustomerEvent(tmpCustomerEvent);

            //Update EventUser
            var tmpEventUser = _eventUserService.GetEventUserById(tmpCustomerEvent.EventUserId);

            tmpEventUser.isStaff = model.CameleoEventUser.isStaff;
            _eventUserService.UpdateEventUser(tmpEventUser);

            // Refresh view
            return(new NullJsonResult());
        }
示例#2
0
        public ActionResult Accept(CameleoCustomerEventViewModel model)
        {
            //Get customer event
            var tmpCustomerEvent = _customerEventService.GetCustomerEventById(model.Id);

            //Accept
            tmpCustomerEvent.Accepted       = true;
            tmpCustomerEvent.AcceptedStatus = (int)AcceptedStatus.AcceptedPaid;

            //Staff user?
            var  tmpEventUser = _eventUserService.GetEventUserById(tmpCustomerEvent.EventUserId);
            bool isStaff      = false;

            if (!(tmpEventUser == null))
            {
                if (tmpEventUser.isStaff)
                {
                    //Yes
                    //Don't make him pay
                    isStaff = true;
                    tmpCustomerEvent.Paid = true;
                }
            }

            //Update customer event
            _customerEventService.UpdateCustomerEvent(tmpCustomerEvent);

            //Model
            CameleoCustomerEventViewModel customerEventViewModel = _customerEventService.GetCustomerEventViewModel(model.Id);

            //Online payment and not staff?
            if (!isStaff && customerEventViewModel.CameleoEvent.OnlinePaymentEnabled)
            {
                //Add product to cart
                var product = _productService.GetProductBySku(CameleoEventProducts.PRODUCT_VIDEO_PROJECT);
                if (product == null)
                {
                    //Product not found
                    customerEventViewModel.Result = _localizationService.GetResource("plugins.cameleo.cameleocustomerevents.videoprojectproduct.notfound");
                }
                else
                {
                    //Add to cart
                    decimal configuredPrice = customerEventViewModel.CameleoEvent.ParticipationFee.HasValue ? customerEventViewModel.CameleoEvent.ParticipationFee.Value : product.Price;

                    var warnings = _shoppingCartService.AddToCart(_workContext.CurrentCustomer, product, ShoppingCartType.ShoppingCart, _storeContext.CurrentStore.Id, string.Empty, configuredPrice, 1, true);
                    if (warnings.Count == 0)
                    {
                        //Get last added cart item
                        var cart = _workContext.CurrentCustomer.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
                        customerEventViewModel.Result = _localizationService.GetResource("plugins.cameleo.cameleocustomerevents.videoprojectproduct.adderror");
                        _logger.Error(_localizationService.GetResource("plugins.cameleo.cameleocustomerevents.videoprojectproduct.adderror") + " " + warnings.ToString());
                    }
                }

                if (string.IsNullOrEmpty(customerEventViewModel.Result))
                {
                    //No errors

                    //Redirect
                    return(View("~/Plugins/Cameleo.CameleoEvents/Views/CameleoEvents/CustomerEvent/ImageUse.cshtml", customerEventViewModel));
                }
            }

            //Else show payment page
            ViewBag.CustomerEventId = tmpCustomerEvent.Id;
            ViewBag.CustomerId      = tmpCustomerEvent.CustomerId;

            if (isStaff)
            {
                //Yes
                //Go to event details
                return(EventDetails(tmpCustomerEvent.Id));
            }

            //Return view
            return(View("~/Plugins/Cameleo.CameleoEvents/Views/CameleoEvents/PaymentInfo/PaymentInfo.cshtml", customerEventViewModel));
        }