public async Task <IActionResult> Download(string id)
        {
            if (id == null)
            {
                return(Content("filename not present"));
            }

            int idInt = 0;

            int.TryParse(id, out idInt);

            var document = _dbContext.tbl_Documents.Where(w => w.DocumentId == idInt).FirstOrDefault();

            if (document == null)
            {
                return(Content("filename not present"));
            }

            DocumentUtility _documentUtility = new DocumentUtility();

            var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Document", document.FileName);
            var memory = new MemoryStream();

            using (var stream = new FileStream(path, FileMode.Open)) { stream.CopyTo(memory); }
            memory.Position = 0;
            return(File(memory, _documentUtility.GetContentType(path), Path.GetFileName(path)));
        }
        public void InitView()
        {
            if (!string.IsNullOrEmpty(_model.Invoice.Cpf) && DocumentUtility.IsCpfValid(_model.Invoice.Cpf))
            {
                _model.User = new User {
                    Cpf = _model.Invoice.Cpf
                };

                if (OnStepCompletedEventHandler != null)
                {
                    OnStepCompletedEventHandler();
                }
            }

            _view.InitInstruction = AppConfigUtility.sMessageInformCpf;
            _view.SetFocus();
            _view.SetEnabled(true);

            if (OnStepStartTimeoutEventHandler != null)
            {
                TimeoutHandler = new Timer {
                    Interval = AppConfigUtility.iNoInteractionTimeOut
                };

                OnStepStartTimeoutEventHandler();
            }
        }
        private Invoice GetInvoiceFromQrCode(string sQrCode)
        {
            var oInvoice = new Invoice();
            var oKeys    = ParseQrCodeInput(sQrCode);

            if (oKeys == null)
            {
                return(null);
            }
            if (!oKeys.ContainsKey("chNFe"))
            {
                return(null);
            }
            if (!oKeys.ContainsKey("nVersao"))
            {
                return(null);
            }
            if (!oKeys.ContainsKey("tpAmb"))
            {
                return(null);
            }
            if (!oKeys.ContainsKey("dhEmi"))
            {
                return(null);
            }
            if (!oKeys.ContainsKey("vNF"))
            {
                return(null);
            }
            if (!oKeys.ContainsKey("vICMS"))
            {
                return(null);
            }
            if (!oKeys.ContainsKey("digVal"))
            {
                return(null);
            }
            if (!oKeys.ContainsKey("cIdToken"))
            {
                return(null);
            }
            if (!oKeys.ContainsKey("cHashQRCode"))
            {
                return(null);
            }

            oInvoice.QrCode     = oKeys["QrCode"];
            oInvoice.HashQrCode = oKeys["cHashQRCode"];
            oInvoice.Cpf        = oKeys.ContainsKey("cDest") ? DocumentUtility.IsCpfValid(oKeys["cDest"]) ? oKeys["cDest"] : string.Empty : string.Empty;
            oInvoice.Cnpj       = oKeys["chNFe"].Substring(6, 14);
            oInvoice.Value      = Convert.ToDecimal(oKeys["vNF"].Replace('.', ','));
            oInvoice.Icms       = Convert.ToDecimal(oKeys["vICMS"].Replace('.', ','));

            return(oInvoice);
        }
        public void Add(OutreachDTO entry)
        {
            string user = Membership.GetUser().UserName;

            if (entry.OutreachType.Id == 1)
            {
                if (!string.IsNullOrEmpty(entry.EmailRecipient) || !string.IsNullOrEmpty(entry.EmailBody) || entry.PersonaId > 0)
                {
                    if (string.IsNullOrEmpty(entry.EmailRecipient) || string.IsNullOrEmpty(entry.EmailBody) || entry.PersonaId < 1)
                    {
                        throw new Exception("Recipient, Sender, and Email Content must all be populated before sending an email.");
                    }
                    else
                    {
                        string attachmentPath = null;

                        if (entry.ArticleId > 0)
                        {
                            ArticleRepository articleRepo = new ArticleRepository();
                            ArticleDTO        article     = articleRepo.GetArticleById(entry.ArticleId);
                            DocumentUtility   docUtil     = new DocumentUtility();
                            attachmentPath = docUtil.ConvertHtmlToDocPath(new DocumentDTO()
                            {
                                Title = article.Title, Content = article.Content
                            });
                        }

                        PersonaDTO persona = new PersonaRepository().GetById(entry.PersonaId);

                        string smtpServer   = persona.SMTPServer;
                        int    smtpPort     = persona.SMTPPort;
                        string smtpUsername = persona.SMTPUsername;
                        string smtpPassword = persona.SMTPPassword;

                        if (persona.Email.ToLower().Contains("@gmail.com"))
                        {
                            smtpServer   = "smtp.gmail.com";
                            smtpPort     = 587;
                            smtpUsername = persona.GmailUsername;
                            smtpPassword = persona.GmailPassword;
                        }

                        MessagingHelper.SendEmail(persona.Email, entry.EmailRecipient, entry.EmailSubject, entry.EmailBody, attachmentPath, smtpServer, smtpPort, smtpUsername, smtpPassword);
                    }
                }
            }

            repo.AddOutreach(entry, user);
        }
        public ActionResult Add(DocumentViewModel model, IFormFile file)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    DbfunctionUtility dbfunction = new DbfunctionUtility(_appSettings);
                    var     query = "select * from Documents where Name = '" + model.Name + "' and seasonId = " + model.SeasonId + "";
                    DataSet ds    = dbfunction.GetDataset(query);
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        var document = new Document
                        {
                            Name        = model.Name,
                            IsActive    = true,
                            CreatedBy   = UserId,
                            CreatedDate = DateTime.Now,
                            FileName    = file.FileName,
                            Description = model.Description,
                            SeasonId    = model.SeasonId
                        };

                        _dbContext.tbl_Documents.Add(document);
                        _dbContext.SaveChanges();

                        var fileName = document.DocumentId.ToString() + Path.GetExtension(file.FileName);
                        document.FileName = fileName;
                        _dbContext.SaveChanges();
                        DocumentUtility _documentUtility = new DocumentUtility();
                        _documentUtility.SaveFile(document.DocumentId.ToString(), "Document", file);

                        ViewBag.SuccessMessage = "File added successfully";
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "File is already exists";
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(View(model));
        }
        protected override IEnumerable <ValidationResult> ValidateInternal(object value, DocumentValidationContext <TDocument> validationContext)
        {
            var typedValue = value as string;

            if (string.IsNullOrEmpty(typedValue))
            {
                yield break;
            }

            if (!CaseSensitive)
            {
                typedValue = typedValue.ToLower();
            }

            var andClauses = new List <IMongoQuery>();

            andClauses.Add(Query.NE("_id", validationContext.Document.ID));

            andClauses.Add(CaseSensitive
                                ? Query.EQ(_propertyName, BsonValue.Create(typedValue))
                                : Query.Matches(_propertyName, new BsonRegularExpression("^" + Regex.Escape(typedValue) + "$", "i")));

            if (Scope != null && Scope.Length > 0)
            {
                foreach (var scopeProperty in Scope)
                {
                    string scopePropertyName  = ExpressionUtility.GetPropertyName(scopeProperty);
                    object scopePropertyValue = scopeProperty.Compile()(validationContext.Document);
                    if (scopePropertyValue != null &&
                        ReflectionUtility.IsSubclassOfRawGeneric(typeof(Document <>), scopePropertyValue.GetType()))
                    {
                        scopePropertyValue = DocumentUtility.GetDocumentID(scopePropertyValue);
                    }
                    andClauses.Add(Query.EQ(scopePropertyName, BsonValue.Create(scopePropertyValue)));
                }
            }

            var query   = Query.And(andClauses.ToArray());
            var results = Document <TDocument> .GetCollection().Find(query);

            if (results.Any())
            {
                yield return(new ValidationResult(validationContext.DisplayName + " must be unique"));
            }
        }
        public void HandleCpfInput(string sCpf)
        {
            try
            {
                if (!sCpf.Length.Equals(11))
                {
                    return;
                }

                _view.SetEnabled(false);

                if (DocumentUtility.IsCpfValid(sCpf))
                {
                    _model.User = new User {
                        Cpf = sCpf
                    };

                    if (OnStepCompletedEventHandler != null)
                    {
                        OnStepCompletedEventHandler();
                    }
                }
                else
                {
                    throw new AlertMessageException(AppConfigUtility.sMessageInvalidCpf);
                }
            }
            catch (AlertMessageException ex)
            {
                if (OnStepWarningEventHandler != null)
                {
                    OnStepWarningEventHandler(ex.Message);
                }
            }
            catch (Exception ex)
            {
                LogUtility.Log(LogUtility.LogType.SystemError, MethodBase.GetCurrentMethod().Name, ex.Message);

                if (OnStepErrorEventHandler != null)
                {
                    OnStepErrorEventHandler(AppConfigUtility.sMessageGenericInvoiceError);
                }
            }
        }