예제 #1
0
        public ActionResult Edit(ReplyViewModel model)
        {
            try
            {
                var    item         = _contactLogic.GetById(model.Id);
                string userIdString = User.Identity.GetUserId();
                var    userId       = Convert.ToInt32(userIdString);
                item.Reply       = model.Reply;
                item.RepliedDate = DateTime.Now;
                item.Status      = Constant.ContactStatus.REPLIED;
                item.ReplyUserId = userId;
                var response = _contactLogic.Edit(item);
                if (response.IsError == true)
                {
                    foreach (var error in response.ErrorCodes)
                    {
                        ModelState.AddModelError(string.Empty, error);
                    }
                    return(View(model));
                }
                else
                {
                    var msg = new MailMessage();
                    msg.To.Add(new MailAddress(item.Email));
                    msg.Subject    = "E-SINERGI Admin";
                    msg.IsBodyHtml = true;
                    msg.Body       = "Isi kontak anda: <br />" + item.Content + "<br />Balasan: <br />" + model.Reply;
                    msg.From       = new MailAddress("*****@*****.**");

                    using (var client = new SmtpClient()
                    {
                        Host = "relay-hosting.secureserver.net", Port = 25, EnableSsl = false, UseDefaultCredentials = false
                    })
                    {
                        client.Send(msg);
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }