コード例 #1
0
        public async Task<IHttpActionResult> SupportMessage(SupportModel model)
        {
            try
            {
                //var userId = User.Identity.GetUserId();
                //var user = await _Uow._Users.GetAll(x => x.Id == userId).FirstOrDefaultAsync();

                ////Assign the smtp credentials for gmail
                //SmtpClient smtp = new SmtpClient();
                //if (true)
                //{
                //    smtp.Host = "mail.ps-demo.com";
                //    smtp.Port = 25;
                //    smtp.Credentials = new NetworkCredential("*****@*****.**", "@Dmin123");
                //    smtp.Timeout = 20000;
                //}

                //MailAddress fromAddress = new MailAddress("*****@*****.**", "Support Request From " + user.FullName);
                //MailAddress toAddress = new MailAddress("*****@*****.**");

                ////Passing values to smtp object
                //dynamic message = new MailMessage(fromAddress, toAddress);
                //message.Subject = model.Subject;

                //var sb = new StringBuilder("");
                //sb.Append("<b>From : </b>" + user.Email);
                //sb.Append("<br />");
                //sb.Append("<b>Time : </b>" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
                //sb.Append("<br />");
                //sb.Append("<b>Name : </b>" + user.FullName);
                //sb.Append("<br />");
                //sb.Append("<h3>Message</h3>");
                //sb.Append(model.Message);
                //message.Body = sb.ToString();
                //message.IsBodyHtml = true;


                ////Send email
                //smtp.Send(message);
                //return Ok();

                var message = new SupportMessage();
                message.Active = true;
                message.FromUserId = User.Identity.GetUserId();
                message.IsFromAdmin = false;
                message.IsFromUser = true;
                message.IsRead = false;
                message.MessageDatetime = DateTime.UtcNow;
                message.MessageText = model.Message;

                _Uow._SupportMessages.Add(message);
                await _Uow.CommitAsync();

                var messageModel = new UserMessagesModel();
                messageModel.Id = message.Id;
                messageModel.IsFromAdmin = message.IsFromAdmin.GetValueOrDefault();
                messageModel.IsFromUser = message.IsFromUser.GetValueOrDefault();
                messageModel.IsRead = message.IsRead.GetValueOrDefault();
                messageModel.MessageDateTime = message.MessageDatetime.GetValueOrDefault();
                messageModel.MessageText = message.MessageText;

                return Ok(messageModel);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
コード例 #2
0
        public async Task<IHttpActionResult> SupportMessageReply(SupportModel model)
        {
            try
            {

                var message = new SupportMessage();
                message.Active = true;
                message.FromUserId = User.Identity.GetUserId();
                message.IsFromAdmin = true;
                message.IsFromUser = false;
                message.IsRead = false;
                message.MessageDatetime = DateTime.UtcNow;
                message.MessageText = model.Message;
                message.ToUserId = model.ToUserId;

                _Uow._SupportMessages.Add(message);
                await _Uow.CommitAsync();

                var messageModel = new UserMessagesModel();
                messageModel.Id = message.Id;
                messageModel.IsFromAdmin = message.IsFromAdmin.GetValueOrDefault();
                messageModel.IsFromUser = message.IsFromUser.GetValueOrDefault();
                messageModel.IsRead = message.IsRead.GetValueOrDefault();
                messageModel.MessageDateTime = message.MessageDatetime.GetValueOrDefault();
                messageModel.MessageText = message.MessageText;

                await LogHelpers.SaveLog(_Uow, "Reply To Message. Reply : " + model.Message, User.Identity.GetUserId());

                return Ok(messageModel);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }