Beispiel #1
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));
        }
Beispiel #2
0
        public virtual void ImportEventUsersFromXlsx(Stream stream, int eventId)
        {
            using (var xlPackage = new ExcelPackage(stream))
            {
                // get the first worksheet in the workbook
                var worksheet = xlPackage.Workbook.Worksheets.FirstOrDefault();
                if (worksheet == null)
                {
                    //Worksheet not found
                    throw new NopException("No worksheet found");
                }

                //the columns
                var properties = new string[]
                {
                    "UserName",
                    "Password",
                    "LastName",
                    "FirstName",
                    "Email",
                    "ClientUniqueId",
                    "ClientGroup",
                    "SuperiorName",
                    "IsStaff",
                };

                int iRow = 2;
                while (true)
                {
                    //Get column values
                    bool allColumnsAreEmpty = true;
                    for (var i = 1; i <= properties.Length; i++)
                    {
                        if (worksheet.Cells[iRow, i].Value != null && !String.IsNullOrEmpty(worksheet.Cells[iRow, i].Value.ToString()))
                        {
                            allColumnsAreEmpty = false;
                            break;
                        }
                    }
                    if (allColumnsAreEmpty)
                    {
                        //Empty file
                        break;
                    }

                    //Get info from file
                    string userName       = worksheet.Cells[iRow, GetColumnIndex(properties, "UserName")].Value.ToString();
                    string password       = worksheet.Cells[iRow, GetColumnIndex(properties, "Password")].Value.ToString();
                    string lastName       = worksheet.Cells[iRow, GetColumnIndex(properties, "LastName")].Value == null ? null : worksheet.Cells[iRow, GetColumnIndex(properties, "LastName")].Value.ToString();
                    string firstName      = worksheet.Cells[iRow, GetColumnIndex(properties, "FirstName")].Value == null ? null : worksheet.Cells[iRow, GetColumnIndex(properties, "FirstName")].Value.ToString();
                    string email          = worksheet.Cells[iRow, GetColumnIndex(properties, "Email")].Value == null ? null : worksheet.Cells[iRow, GetColumnIndex(properties, "Email")].Value.ToString();
                    string clientUniqueId = worksheet.Cells[iRow, GetColumnIndex(properties, "ClientUniqueId")].Value == null ? null : worksheet.Cells[iRow, GetColumnIndex(properties, "ClientUniqueId")].Value.ToString();
                    string clientGroup    = worksheet.Cells[iRow, GetColumnIndex(properties, "ClientGroup")].Value == null ? null : worksheet.Cells[iRow, GetColumnIndex(properties, "ClientGroup")].Value.ToString();
                    string superiorName   = worksheet.Cells[iRow, GetColumnIndex(properties, "SuperiorName")].Value == null ? null : worksheet.Cells[iRow, GetColumnIndex(properties, "SuperiorName")].Value.ToString();
                    bool   isStaff        = Convert.ToBoolean(worksheet.Cells[iRow, GetColumnIndex(properties, "IsStaff")].Value);

                    //Event user exists?
                    var  eventUser    = _eventUserService.GetEventUserByUserName(userName);
                    bool newEventUser = false;
                    if (eventUser == null)
                    {
                        //No, new event user
                        eventUser    = new CameleoEventUser();
                        newEventUser = true;
                    }

                    //Fill event user
                    eventUser.UserName     = userName;
                    eventUser.Password     = password;
                    eventUser.LastName     = lastName;
                    eventUser.FirstName    = firstName;
                    eventUser.Email        = email;
                    eventUser.UniqueId     = clientUniqueId;
                    eventUser.Group        = clientGroup;
                    eventUser.SuperiorName = superiorName;
                    eventUser.isStaff      = isStaff;

                    //EventId
                    eventUser.EventId = eventId;

                    //Create date
                    eventUser.CreatedOnUtc = DateTime.Now;

                    //New?
                    if (newEventUser)
                    {
                        //Yes
                        //Insert
                        _eventUserService.InsertEventUser(eventUser);
                    }
                    else
                    {
                        //Else update
                        _eventUserService.UpdateEventUser(eventUser);
                    }

                    //next product
                    iRow++;
                }
            }
        }