예제 #1
0
        public string Send()
        {
            string retorno = string.Empty;

            Message.BodyEncoding = UTF8Encoding.UTF8;
            Message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            Message.From = new System.Net.Mail.MailAddress(FromAddress);

            FileAttached.ToList().ForEach(x => Message.Attachments.Add(new System.Net.Mail.Attachment(x)));

            ToAddress.ToList().ForEach(x => Message.To.Add(new System.Net.Mail.MailAddress(x)));

            ToAddressCopy.ToList().ForEach(x => Message.CC.Add(new System.Net.Mail.MailAddress(x)));

            Message.Subject            = Subject;
            Message.Body               = Body;
            Smtp.UseDefaultCredentials = false;
            Smtp.Timeout               = 180000;
            Smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;

            Smtp.Credentials = new System.Net.NetworkCredential(Acount, PassWord);

            try
            {
                Smtp.Send(Message);
                retorno = "";
            }
            catch (Exception ex_)
            {
                retorno = ex_.InnerException != null ? (ex_.InnerException).Message : ex_.Message;
            }

            return(retorno);
        }
예제 #2
0
        public async Task OnPostCreateAttachment()
        {
            // Check if a) a file is attached and b) if it's an xlsx or not, before processing. Otherwise it will throw error.
            if (FileAttached != null)
            {
                // Name the file
                Attachment.FilePath = Path.Combine(@"\\ahmtroy03\sppcsharedfiles\6290 Procurement Operations\_Public\Data\Crisis\COVID-19\Attachments",
                                                   Attachment.SupplierId + "_" + DateTime.Now.ToString("yyyy-MM-dd_hhmmsstt") + "_" + FileAttached.FileName);

                // Save the file and update models
                using var fileStream = new FileStream(Attachment.FilePath, FileMode.Create, FileAccess.ReadWrite);
                try
                {
                    await FileAttached.CopyToAsync(fileStream);

                    fileStream.Dispose();
                }
                catch (Exception ex)
                {
                    if (ex.Message == "Object reference not set to an instance of an object.")
                    {
                        StatusMessage = "Error: Check your file and try again";
                    }
                    else
                    {
                        StatusMessage = "Error: An error occured while importing. " + ex.Message;
                    }
                }
            }
            else
            {
                StatusMessage = "Error: Please attaching file.";
            }

            if (!ModelState.IsValid)
            {
                //This is here just in case I figure this out but for some reason it doesn't acknowledge the FilePath even though it's there.
            }

            _context.Attachment.Add(Attachment);
            await _context.SaveChangesAsync();

            StatusMessage = "Attachment added!";
            await OnGetAsync();
        }
예제 #3
0
        public ActionResult AdjuntoDelete([DataSourceRequest] DataSourceRequest request, FileAttached model)
        {
            if (model != null && ModelState.IsValid)
            {
                IRestResponse WSR = Task.Run(() => apiClient.postObject("Adjunto/Eliminar", model)).Result;
                if (WSR.StatusCode != HttpStatusCode.OK)
                {
                    ModelState.AddModelError("errorGeneral", JObject.Parse(WSR.Content).ToObject <Error>().Message.ToString());
                }
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
예제 #4
0
        public ActionResult AdjuntoUpdate([DataSourceRequest] DataSourceRequest request, FileAttached model, FormCollection frmcol)
        {
            List <Field> fields = (List <Field>)Session["FIELDS"];

            if (String.IsNullOrEmpty(frmcol["AttachedDate"].ToString()) || String.IsNullOrWhiteSpace(frmcol["AttachedDate"].ToString()))
            {
                ModelState.AddModelError("RateDate", "Formato de fecha incorrecta");
            }
            else
            {
                model.AttachedDate = Convert.ToDateTime(frmcol["AttachedDate"].ToString().Substring(0, 10));
                ModelState.Clear();
            }

            fields.ForEach(x => {
                if (x.IsRequeried)
                {
                    switch (x.DataBaseName)
                    {
                    case "Description":
                        if (String.IsNullOrEmpty(model.Description) || String.IsNullOrWhiteSpace(model.Description))
                        {
                            ModelState.AddModelError("Description", "*");
                        }
                        break;

                    case "AttachedNumber":
                        if (String.IsNullOrEmpty(model.AttachedNumber) || String.IsNullOrWhiteSpace(model.AttachedNumber))
                        {
                            ModelState.AddModelError("AttachedNumber", "*");
                        }
                        break;

                    case "AttachedDate":
                        if (model.AttachedDate == null)
                        {
                            ModelState.AddModelError("AttachedDate", "*");
                        }
                        break;
                    }
                }
            });

            model.IdFileHeader = (Int32)Session["IDFILEHEADER"];
            model.IdSupplier   = (model.IdSupplier == null) ? Convert.ToInt32(frmcol["IdSupplierOrDestiny.Id"]) : ((model.IdSupplier == 0) ? Convert.ToInt32(frmcol["IdSupplierOrDestiny.Id"]) : model.IdSupplier);

            if (model.IdSupplier == 0 || model.IdSupplier == null)
            {
                ModelState.AddModelError("IdSupplier", "*");
            }

            if (model != null && ModelState.IsValid)
            {
                model.RegisterUser = ((Commons.User)Session["USERINFO"]).UserName;
                IRestResponse WSR = Task.Run(() => apiClient.postObject("Adjunto/Modificar", model)).Result;
                if (WSR.StatusCode != HttpStatusCode.OK)
                {
                    ModelState.AddModelError("errorGeneral", JObject.Parse(WSR.Content).ToObject <Error>().Message.ToString());
                }
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
예제 #5
0
 public void ClearAttachment()
 {
     FileAttached.Clear();
 }
예제 #6
0
 public void AddAttachment(string pFileAttached)
 {
     FileAttached.Add(pFileAttached);
 }