コード例 #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> LoadUserMessages()
        {
            try
            {
                var userId = User.Identity.GetUserId();
                var messagesList = new List<UserMessagesModel>();

                var messages = await _Uow._SupportMessages
                                .GetAll(x => x.FromUserId == userId || x.ToUserId == userId)
                                .Include(x => x.AspNetUser).ToListAsync();

                foreach (var message in messages)
                {
                    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;
                    messageModel.ReplierName = message.AspNetUser.FullName;

                    messagesList.Add(messageModel);

                    if (message.IsFromAdmin.Value && message.IsRead == false)
                    {
                        message.IsRead = true;
                        _Uow._SupportMessages.Update(message);
                    }
                }

                await _Uow.CommitAsync();
                return Ok(messagesList);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
コード例 #3
0
        public async Task<IHttpActionResult> GetUserMessages(string userId)
        {
            try
            {

                var user = await _Uow._Users.GetAll(x => x.Id == userId).FirstOrDefaultAsync();

                var messagesList = new List<UserMessagesModel>();

                var messages = await _Uow._SupportMessages
                                .GetAll(x => x.FromUserId == userId || x.ToUserId == userId).ToListAsync();

                foreach (var message in messages)
                {
                    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;

                    messagesList.Add(messageModel);


                }

                foreach (var message in messages)
                {
                    if (message.IsFromUser.Value && message.IsRead == false)
                    {
                        message.IsRead = true;
                        _Uow._SupportMessages.Update(message);
                    }
                }

                await _Uow.CommitAsync();

                //await LogHelpers.SaveLog(_Uow, "View All Messages Of " + user.UserName, User.Identity.GetUserId());

                return Ok(messagesList);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
コード例 #4
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);
            }
        }