Ejemplo n.º 1
0
        public ActionResult NewEntry(int type)
        {
            var model = new SubmissionRecord
            {
                Email          = _workContext.CurrentCustomer.Email,
                FullName       = _workContext.CurrentCustomer.GetFullName(),
                RecordType     = type,
                DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult SubmissionUpdate(SubmissionRecord submissionUpdate)
        {
            var submissionRec = _submissionRepo.GetById(submissionUpdate.SubmissionRecordId);

            submissionRec.Email        = submissionUpdate.Email;
            submissionRec.FullName     = submissionUpdate.FullName;
            submissionRec.Subject      = submissionUpdate.Subject;
            submissionRec.Phone        = submissionUpdate.Phone;
            submissionRec.Enquiry      = submissionUpdate.Enquiry;
            submissionRec.DownloadLink = submissionUpdate.DownloadLink;
            submissionRec.RecordType   = submissionUpdate.RecordType;

            _submissionRepo.Update(submissionRec);

            return(new NullJsonResult());
        }
Ejemplo n.º 3
0
        private void ProcessFileUpload(SubmissionRecord sr, out string errorMessage, out string fileName, out int downloadId)
        {
            Stream stream = null;

            fileName   = String.Empty;
            downloadId = 0;
            var contentType = String.Empty;

            errorMessage = String.Empty;

            //Check in IE if we have submitted file
            if (String.IsNullOrEmpty(Request["qqfile"]) && Request.Files.Count > 0)
            {
                HttpPostedFileBase httpPostedFile = Request.Files[0];
                stream      = httpPostedFile.InputStream;
                fileName    = Path.GetFileName(httpPostedFile.FileName);
                contentType = httpPostedFile.ContentType;
            }
            //check in Webkit, Mozilla if we have submitted file
            else if (Request.InputStream != null && Request["qqfile"] != null)
            {
                stream   = Request.InputStream;
                fileName = Request["qqfile"];
            }

            //check if we do not have any file submitted for upload -> exit this method
            if (stream == null || stream.Length == 0)
            {
                return;
            }

            var fileBinary = new byte[stream.Length];

            stream.Read(fileBinary, 0, fileBinary.Length);

            var fileExtension = Path.GetExtension(fileName);

            if (!String.IsNullOrEmpty(fileExtension))
            {
                fileExtension = fileExtension.ToLowerInvariant();
            }

            //verify if file size does not exceed maximum defined in the admin area
            int maxFileSize = EngineContext.Current.Resolve <SubmissionAdminSettings>().SubmissionFileMaxSizeInMB;

            if (fileBinary.Length > (maxFileSize * 1024 * 1024))
            {
                errorMessage = String.Format(_localizationService.GetResource("Plugins.Zingasoft.Submission.Error.MaxSizeExeeded"), maxFileSize);
                return;
            }

            //verify if file type exists amongst the allowed file types defined in the admin area
            string allowedFileTypes = EngineContext.Current.Resolve <SubmissionAdminSettings>().SubmissionAllowedFiletypes;

            string[] splitFileTypes = allowedFileTypes.Split(',');
            bool     isAllowed      = false;

            foreach (var item in splitFileTypes)
            {
                if (item.Trim().ToLower().CompareTo(fileExtension.ToLower()) == 0)
                {
                    isAllowed = true;
                    break;
                }
            }
            if (isAllowed == false)
            {
                errorMessage = String.Format(_localizationService.GetResource("Plugins.Zingasoft.Submission.Error.InvalidFiletype"), allowedFileTypes);
                return;
            }

            //if we have passed all of the above verifications -> we can save the download in the DB
            var download = new Download
            {
                DownloadGuid   = Guid.NewGuid(),
                UseDownloadUrl = false,
                DownloadUrl    = String.Empty,
                DownloadBinary = fileBinary,
                ContentType    = contentType,
                //we store filename without extension for downloads
                Filename  = Path.GetFileNameWithoutExtension(fileName),
                Extension = fileExtension,
                IsNew     = true
            };

            _downloadService.InsertDownload(download);

            //assign the download link to the submissionrecord object
            sr.DownloadLink = Url.Action("GetFileUpload", "Download", new { downloadId = download.DownloadGuid });
            downloadId      = download.Id;
        }
Ejemplo n.º 4
0
        public ActionResult NewEntry(SubmissionRecord sr, bool captchaValid)
        {
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

            if (ModelState.IsValid)
            {
                string fileUploadErrorMessage = String.Empty;
                string filename   = String.Empty;
                int    downloadId = 0;
                ProcessFileUpload(sr, out fileUploadErrorMessage, out filename, out downloadId);

                //check if the file upload process went OK
                if (String.IsNullOrEmpty(fileUploadErrorMessage))
                {
                    string to = String.Empty;
                    switch (sr.RecordType)
                    {
                    case (int)SubmissionType.Enquiry:
                        to = EngineContext.Current.Resolve <SubmissionAdminSettings>().EnquiryEmail;
                        break;

                    case (int)SubmissionType.JobApplication:
                        to = EngineContext.Current.Resolve <SubmissionAdminSettings>().JobApplicationEmail;
                        break;

                    case (int)SubmissionType.PartnerOffer:
                        to = EngineContext.Current.Resolve <SubmissionAdminSettings>().PartnerOfferEmail;
                        break;

                    case (int)SubmissionType.VendorOffer:
                        to = EngineContext.Current.Resolve <SubmissionAdminSettings>().VendorOfferEmail;
                        break;

                    case (int)SubmissionType.Other:
                        to = EngineContext.Current.Resolve <SubmissionAdminSettings>().OtherEmail;
                        break;

                    default:
                        break;
                    }

                    //if we have a subscriber => we send the email
                    if (String.IsNullOrEmpty(to) == false)
                    {
                        string[]      toList = to.Split(';');
                        List <string> cc     = null;
                        if (toList.Length > 1)
                        {
                            to = toList[0];

                            cc = new List <string>();
                            for (int i = 1; i < toList.Length - 1; i++)
                            {
                                cc.Add(toList[i]);
                            }
                        }
                        string email    = sr.Email.Trim();
                        string fullName = sr.FullName;
                        string subject  = sr.Subject;

                        var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                        if (emailAccount == null)
                        {
                            emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                        }
                        if (emailAccount == null)
                        {
                            throw new Exception("No email account could be loaded");
                        }

                        StringBuilder sb = new StringBuilder();
                        sb.Append(_localizationService.GetResource("Plugins.Zingasoft.Submission.Admin.EmailNotificationIntro"));
                        sb.Append("<br/><br/>");
                        sb.Append(_localizationService.GetResource("Plugins.Zingasoft.Submission.EmailLabel"));
                        sb.Append(": ");
                        sb.Append(Core.Html.HtmlHelper.FormatText(sr.Email, false, true, false, false, false, false));
                        sb.Append("<br/>");
                        sb.Append(_localizationService.GetResource("Plugins.Zingasoft.Submission.FullNameLabel"));
                        sb.Append(": ");
                        sb.Append(Core.Html.HtmlHelper.FormatText(sr.FullName, false, true, false, false, false, false));
                        sb.Append("<br/>");
                        sb.Append(_localizationService.GetResource("Plugins.Zingasoft.Submission.SubjectLabel"));
                        sb.Append(": ");
                        sb.Append(Core.Html.HtmlHelper.FormatText(sr.Subject, false, true, false, false, false, false));
                        sb.Append("<br/>");
                        if (String.IsNullOrEmpty(sr.Phone) == false)
                        {
                            sb.Append(_localizationService.GetResource("Plugins.Zingasoft.Submission.PhoneLabel"));
                            sb.Append(": ");
                            sb.Append(Core.Html.HtmlHelper.FormatText(sr.Phone, false, true, false, false, false, false));
                            sb.Append("<br/>");
                        }
                        sb.Append(_localizationService.GetResource("Plugins.Zingasoft.Submission.EnquiryLabel"));
                        sb.Append(": ");
                        sb.Append(Core.Html.HtmlHelper.FormatText(sr.Enquiry, false, true, false, false, false, false));

                        string body = sb.ToString();
                        try
                        {
                            _emailSender.SendEmail(emailAccount,
                                                   sr.Subject,
                                                   body,
                                                   sr.Email,
                                                   sr.FullName,
                                                   to,
                                                   to,
                                                   to,
                                                   to,
                                                   null,
                                                   cc,
                                                   Url.Content(String.Format("~{0}", sr.DownloadLink)),
                                                   filename,
                                                   downloadId);
                        }
                        catch (Exception exc)
                        {
                            _logger.Error(string.Format("Error sending e-mail. {0}", exc.Message), exc);
                        }
                    }

                    _submissionRepo.Insert(sr);

                    sr.SuccessfullySaved = true;
                    sr.SaveResult        = _localizationService.GetResource("Plugins.Zingasoft.Submission.Info.SubmissionSucceeded");

                    return(View(sr));
                }
                else
                {
                    ModelState.AddModelError("", fileUploadErrorMessage);
                }
            }

            return(View(sr));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method will register a logger on the MUX logger and then raise a build started event if the build started event has already been logged
        /// </summary>
        public void RegisterLogger(int submissionId, ILogger logger)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            if (_eventSourceForBuild == null)
            {
                throw new InvalidOperationException("Cannot register a logger before the MuxLogger has been initialized.");
            }

            if (_submissionProjectsInProgress.ContainsKey(submissionId))
            {
                throw new InvalidOperationException("Cannot register a logger for a submission once it has started.");
            }

            // See if another logger has been registered already with the same submission ID
            SubmissionRecord record = null;
            lock (_submissionRecords)
            {
                if (!_submissionRecords.TryGetValue(submissionId, out record))
                {
                    record = new SubmissionRecord(submissionId, _eventSourceForBuild, _buildStartedEvent, _maxNodeCount);
                    _submissionRecords.Add(submissionId, record);
                }
            }

            record.AddLogger(logger);
        }