Example #1
0
        public ActionResult AddCustomerEventPopup(string btnId, string formId, AddCustomerEventViewModel model)
        {
            //Event
            model.CameleoEvent = _eventService.GetEventViewModel(model.CameleoEvent.Id);

            //Get user events for this group
            model.CameleoEventUserList = _eventUserService.GetEventUserListViewModel(model.CameleoEvent.Id, model.GroupName);

            //Get customer events for this group
            model.CameleoCustomerEventList = _customerEventService.GetCustomerEventListViewModel(model.CameleoEvent.Id, model.GroupName);

            ModelState.Clear();

            var tmpCustomer = _customerService.GetCustomerByUsername(model.AddedCustomerEventUserName);

            if (tmpCustomer == null)
            {
                //No customer found with the specified username
                ModelState.AddModelError("", _localizationService.GetResource("Nop.Plugin.Cameleo.CameleoEvents.Views.Admin.AddCustomerEventPopup.UnknownCustomer"));
            }

            if (ModelState.IsValid)
            {
                //Event user already there for this customer?
                if (_customerEventService.GetCustomerEvent(model.AddedEventUserId, tmpCustomer.Id) != null)
                {
                    //Yes,display message
                    ModelState.AddModelError("", _localizationService.GetResource("Nop.Plugin.Cameleo.CameleoEvents.Views.Admin.AddCustomerEventPopup.CustomerEventExists"));
                }
            }

            if (ModelState.IsValid)
            {
                //Everything is fine
                //Add the customer event
                _customerEventService.InsertCustomerEvent(model.AddedEventUserId, tmpCustomer.Id, model.AddedAcceptedStatus, model.AddedAcceptedImageUse);

                //Close popup and refresh list
                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View("~/Plugins/Cameleo.CameleoEvents/Views/Admin/CustomerEvent/AddCustomerEventPopup.cshtml", model));
            }

            //If we got this far, something failed, redisplay form
            return(View("~/Plugins/Cameleo.CameleoEvents/Views/Admin/CustomerEvent/AddCustomerEventPopup.cshtml", model));
        }
Example #2
0
        public ActionResult EventList(CameleoCustomerEventListViewModel model)
        {
            String Result = "";

            if (ModelState.IsValid)
            {
                //Find event user
                var tmpEventUser = _eventUserService.GetEventUserByUserName(model.NewCustomerEvent);
                if (tmpEventUser == null)
                {
                    //Not found
                    Result = _localizationService.GetResource("Plugins.Cameleo.CameleoEventUsers.NotFound");
                }
                else
                {
                    //Else found

                    //Check password
                    if (tmpEventUser.Password == model.Password)
                    {
                        //Password ok

                        //Check if already added
                        var tmpCustomerEvent = _customerEventService.GetCustomerEvent(tmpEventUser.Id, _workContext.CurrentCustomer.Id);
                        if (tmpCustomerEvent != null)
                        {
                            //Customer event already present
                            Result = _localizationService.GetResource("Plugins.Cameleo.CameleoCustomerEvents.Exists");
                        }
                        else
                        {
                            // Else try to add it
                            try
                            {
                                _customerEventService.InsertCustomerEvent(tmpEventUser.Id, _workContext.CurrentCustomer.Id);

                                //Go to details
                                var tmpUser = _customerEventService.GetCustomerEvent(tmpEventUser.Id, _workContext.CurrentCustomer.Id);
                                if (tmpUser != null)
                                {
                                    Result = _localizationService.GetResource("Plugins.Cameleo.CameleoCustomerEvents.InsertSuccess");
                                    return(RedirectToRoute("CameleoEventDetails", new { customerEventId = tmpUser.Id }));
                                }
                                else
                                {
                                    Result = _localizationService.GetResource("Plugins.Cameleo.CameleoCustomerEvents.InsertError");
                                }
                            }
                            catch (Exception)
                            {
                                Result = _localizationService.GetResource("Plugins.Cameleo.CameleoCustomerEvents.InsertError");
                            }
                        }
                    }
                    else
                    {
                        //Else wrong password
                        Result = _localizationService.GetResource("Plugins.Cameleo.CameleoEventUsers.WrongPassword");;
                    }
                }
            }

            //Get all events for this customer user
            CameleoCustomerEventListViewModel customerEventListViewModel = _customerEventService.GetCustomerEventListViewModel(_workContext.CurrentCustomer.Id);

            customerEventListViewModel.Result = Result;

            //Redisplay form
            return(View("~/Plugins/Cameleo.CameleoEvents/Views/CameleoEvents/CustomerEvent/CameleoEvents.cshtml", customerEventListViewModel));
        }