// POST api/<controller>
 public IHttpActionResult Post([FromBody] Message m)
 {
     try
     {
         MessageBL.AddMessage(m);
         return(Ok());
     }
     catch
     {
         throw;
     }
 }
        public ActionResult Create([Bind("MessageInfo")] MessageViewModel mvm)
        {
            try
            {
                var message = mvm.MessageInfo;
                message.SenderId = _userManager.GetUserId(User);
                try
                {
                    if (ModelState.IsValid)
                    {
                        var sent = MessageBL.AddMessage(message);
                        //Display confirmation if a message was sent. To who and when
                        if (sent)
                        {
                            TempData["custdetails"] = string.Format("Message sent to \"{0}\", {1}", message.ReceiverId, DateTime.Now.ToString("HH:mm MM/dd/yyyy"));
                        }
                        else
                        {
                            TempData["custdetails"] = string.Format("Unable to send message to \"{0}\", {1}", message.ReceiverId, DateTime.Now.ToString("HH:mm MM/dd/yyyy"));
                        }

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                catch (DbUpdateException ex)
                {
                    //Log the error (uncomment ex variable name and write a log.
                    Debug.WriteLine(ex.StackTrace);
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists " +
                                             "see your system administrator.");
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
                TempData["sErrMsg"] = e.Message;
                return(RedirectToAction(nameof(Index)));
                //return Redirect("~/");
            }
        }
Example #3
0
    protected void MailGrid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        if (string.IsNullOrEmpty(e.Parameters))
        {
            return;
        }
        var args = e.Parameters.Split('|');

        if (args[0] == "FolderChanged")
        {
            MailGrid.FilterExpression = "";
            BindGrid();
            MailGrid.ExpandAll();
        }
        if (args[0] == "Search")
        {
            if (string.IsNullOrEmpty(SearchText))
            {
                MailGrid.FilterExpression = "";
            }
            CriteriaOperator criteria = new GroupOperator(GroupOperatorType.Or,
                                                          new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty(ShowToColumn() ? "To" : "From"), SearchText),
                                                          new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty("Subject"), SearchText)
                                                          );
            MailGrid.FilterExpression = criteria.ToString();

            BindGrid();
            MailGrid.ExpandAll();
        }
        if (args[0] == "SendMail" || args[0] == "SaveMail")
        {
            var    subject     = SubjectEditor.Text;
            var    to          = ToEditor.Text;
            string messageText = MailEditor.Html.Length <= 10000 ? MailEditor.Html : MailEditor.Html.Substring(0, 10000);
            string folder      = args[0] == "SendMail" ? "Sent Items" : "Drafts";
            int    id;
            if (args.Length == 2 && int.TryParse(args[1], out id))
            {
                MessageBL bl = new MessageBL();
                bl.UpdateMessage(id, subject, to, messageText, folder);
            }
            else
            {
                MessageBL bl      = new MessageBL();
                bool      IsReply = false;
                if (Session["CurrentReplyEmailID"] != null)
                {
                    IsReply = true;
                }
                bl.AddMessage(subject, User.Identity.Name, to, messageText, folder, IsReply);
            }

            Session["CurrentReplyEmailID"] = null;
            BindGrid();
        }
        if (args[0] == "Delete" && args.Length > 1)
        {
            int[] keys = null;
            if (!TryParseKeyValues(args.Skip(1), out keys))
            {
                return;
            }

            MessageBL bl = new MessageBL();

            bl.DeleteMessages(keys);
            BindGrid();
        }
    }
Example #4
0
        protected void SendShippingNoticeEmails(EmailNotificationFormModel model)
        {
            MessageBL MsgBL = new MessageBL();
            TokenBL tBL = new TokenBL();
            List<EmailAttachment> ListWithID = new List<EmailAttachment>();
            int GID = 0;
            string Token = string.Empty;
            int billType = Convert.ToInt32(Session["mailerSelectedBillType"]);

            foreach (var mailItem in model.Items)
            {
                if (mailItem.IsSelected)
                {
                    //Create File Group and get the GID
                    GID = MsgBL.CreateFileAttachmentGroup(User.Identity.Name, model.BillNumber, billType);
                    tBL.CreateToken(ref Token, TokenType.Shipping_Notice, mailItem.RecipientEmail, true, AppConstants.TOKEN_PERIOD_FILE_ACCESS);
                    string Attachments = "<ul>";
                    foreach (var attachment in mailItem.Attachments)
                    {
                        if (attachment.FileID == 0 && attachment.IsSelected)
                        {
                            //Generate PDF files
                            GeneratePDFFiles(attachment, ListWithID);
                            MsgBL.LogFileAttachment(attachment.FileName, attachment.FileID, GID, mailItem.RecipientEmail);
                            Attachments += "<li><a href='" + ConfigurationManager.AppSettings["URL.MailerRedirect.FileViewer"] + "?GID=" + GID + "&FileID=" + attachment.FileID + "&Token=" + Token + "&UserEmail=" + mailItem.RecipientEmail + "'>" + attachment.FileName + "</a></li>";
                        }
                    }
                    Attachments += "</ul>";
                    //Create Links
                    //Create a Token                    
                    //GET MessageTemplate 
                    string emailBody = Email.GetEmailTemplate(Server.MapPath(EmailConstants.PATH_TEMPLATE_SHIPPING_NOTICE));
                    string emailSubject = EmailConstants.SUBJECT_SHIPPING_NOTICE;
                    if (!string.IsNullOrEmpty(mailItem.Subject)) { emailSubject = mailItem.Subject; }
                    EmailMessageTokens tokens = new EmailMessageTokens();
                    var eltuser = GetCurrentELTUser();

                    string sender = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(eltuser.user_fname) +
                    " " + CultureInfo.InvariantCulture.TextInfo.ToTitleCase(eltuser.user_lname);
                    if (string.IsNullOrEmpty(sender.Trim())) sender = User.Identity.Name;
                    tokens.Add(Email.SetEmailMessageToken("CompanyName", eltuser.company_name));
                    tokens.Add(Email.SetEmailMessageToken("SenderName", sender));
                    tokens.Add(Email.SetEmailMessageToken("BillNo", model.BillNumber));
                    tokens.Add(Email.SetEmailMessageToken("MessageBody", mailItem.TextMessage));
                    tokens.Add(Email.SetEmailMessageToken("Attachments", Attachments));

                    //Swap Tokens with data
                    emailBody = Email.ReplaceTokens(emailBody, tokens);
                    //Store Message
                    string Folder = "Shipping Notice";
                    MsgBL.AddMessage(emailSubject, User.Identity.Name, mailItem.RecipientEmail, emailBody, Folder, false);

                    //Store to Sent Itmes 
                    Folder = " Sent Items";
                    MsgBL.AddMessage(emailSubject, User.Identity.Name, mailItem.RecipientEmail, emailBody, Folder, false);

                    //Send email
                    //Get all the CC list
                    List<string> CCList = new List<string>();
                    if (!string.IsNullOrEmpty(mailItem.CC))
                    {
                        mailItem.CC = mailItem.CC.Replace(',', ';');
                        var ccs = mailItem.CC.Split(',');
                        CCList.AddRange(ccs);
                    }
                    try
                    {
                        Email.SendSmtp(mailItem.RecipientEmail, emailSubject, emailBody, true, User.Identity.Name);
                        ViewBag.Message = "Email Sent Successfully!";
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = ex.Message;
                    }
                }

            }
        }
Example #5
0
 public bool Post([FromBody] Message s)
 {
     MessageBL.AddMessage(s);
     return(true);
 }