Example #1
0
 public IActionResult Put(RtRequest updatedRtreq)
 {
     if (ModelState.IsValid)
     {
         db.UpdateRtRequest(updatedRtreq);
         return(Ok());
     }
     return(BadRequest(ModelState));
 }
Example #2
0
        public IActionResult Delete(string id)
        {
            RtRequest rtreq = db.ReadRtRequest(id);

            if (rtreq != null)
            {
                db.DeleteRtRequest(id);
            }
            return(Ok(rtreq));
        }
        public int SendEMailMessageToHQ(string HQeMail, RtRequest request, string credentialsName, string credentialsPass, string smtpHost, string smtpPort, out string resultMessage)
        {
            if (!HQeMail.Equals("") && !credentialsName.Equals("") && !credentialsPass.Equals(""))
            {
                try
                {
                    // отправитель - устанавливаем адрес и отображаемое в письме имя
                    MailAddress from = new MailAddress(credentialsName, "RemTool");

                    // кому отправляем
                    MailAddress to = new MailAddress(HQeMail);

                    // адрес smtp-сервера и порт, с которого будем отправлять письмо
                    SmtpClient smtp = new SmtpClient(smtpHost, int.Parse(smtpPort));

                    // создаем объект сообщения
                    using (MailMessage m = new MailMessage(from, to))
                    {
                        // тема письма
                        m.Subject = "Запрос";

                        // текст письма
                        m.Body = $"<h3>RemTool, запрос от {request.Name}</h3><p>{request.ReqInfo}</p><p>Email:{request.Email}</p>";

                        // письмо представляет код html
                        m.IsBodyHtml = true;

                        // логин и пароль
                        smtp.Credentials = new NetworkCredential(credentialsName, credentialsPass);

                        smtp.EnableSsl = true;
                        //smtp.EnableSsl = false;

                        //smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

                        smtp.Send(m);
                        resultMessage = "1 message to HQ sended";
                        return(1);       // всё хорошо
                    }
                }
                catch (SmtpException smtp_ex)
                {
                    resultMessage = "Error: 2 smtp_ex: " + smtp_ex.Message;
                    return(2);   // ошибка в smtp (в отправке почты)
                }
                catch (Exception ex)
                {
                    resultMessage = "Error: 3 allRound_ex: " + ex.Message;
                    return(3);   // ошибка в чом то ещё - мб формы незаполнены
                }
            }
            resultMessage = "Error: 4 - wrong settings";
            return(4);   // отправки не было, т.к. основные поля отправки невалидны
        }
Example #4
0
 public async Task UpdateRtRequestAsync(RtRequest rtRequest)
 {
     await _rtRequests.ReplaceOneAsync(rtReq => rtReq.Id == rtRequest.Id, rtRequest);
 }
Example #5
0
 public async Task CreateRtRequestAsync(RtRequest rtRequest)
 {
     await _rtRequests.InsertOneAsync(rtRequest);
 }
Example #6
0
 public void UpdateRtRequest(RtRequest rtRequest)
 {
     _rtRequests.ReplaceOne(rtreq => rtreq.Id == rtRequest.Id, rtRequest);
 }
Example #7
0
 public void CreateRtRequest(RtRequest rtRequest)
 {
     _rtRequests.InsertOne(rtRequest);
 }
Example #8
0
        public async Task <IActionResult> Post(RtRequest newRtreq)
        {
            RtMailSettings mSettings = await mailSettings.ReadRtMailSettingsAsync();

            if (ModelState.IsValid)
            {
                var rtReq = await db.ReadRtRequestByEMailAsync(newRtreq.Email);

                if (rtReq != null)
                {
                    // < script >
                    //      var nowDate = new Date();
                    //      var day = nowDate.getDate();
                    //      var mounth = nowDate.getMonth();
                    //      var year = nowDate.getFullYear();
                    //      var hours = nowDate.getHours();
                    //      var minutes = nowDate.getMinutes();
                    //      var time = day + " " + mounth + " " + year + " " + hours + " " + minutes;
                    //      document.write(time);
                    // </ script >


                    if (newRtreq.SendedTime != null && rtReq.SendedTime != null)
                    {
                        var newTime = long.Parse(newRtreq.SendedTime);
                        var oldTime = long.Parse(rtReq.SendedTime);

                        //if (newTime > oldTime + 180)
                        if (newTime > oldTime + 10)
                        {
                            //await db.UpdateRtRequestAsync(new RtRequest
                            //{
                            //    Id = rtReq.Id,
                            //    Name = newRtreq.Name,
                            //    Email = newRtreq.Email,
                            //    Phone = newRtreq.Phone,
                            //    ReqInfo = newRtreq.ReqInfo,
                            //    SendedTime = newRtreq.SendedTime
                            //});
                            db.CreateRtRequest(newRtreq);

                            if (mSettings.SendNotificationToClient == true)
                            {
                                string sendResultMessage;
                                var    sendResult = mailSender.SendEMailMessageToClient(
                                    newRtreq.Email,
                                    mSettings.DefaultMessageToClient,
                                    mSettings.Credentials_Name,
                                    mSettings.Credentials_Pass,
                                    mSettings.SmtpServer_Host,
                                    mSettings.SmtpServer_Port,
                                    out sendResultMessage);
                                if (sendResult != 1)
                                {
                                    return(BadRequest(sendResultMessage));
                                }
                            }
                            if (mSettings.SendNotificationToHQ == true)
                            {
                                string sendResultMessage;
                                var    sendResult = mailSender.SendEMailMessageToHQ(
                                    mSettings.HQeMail,
                                    newRtreq,
                                    mSettings.Credentials_Name,
                                    mSettings.Credentials_Pass,
                                    mSettings.SmtpServer_Host,
                                    mSettings.SmtpServer_Port,
                                    out sendResultMessage);
                                if (sendResult != 1)
                                {
                                    return(BadRequest(sendResultMessage));
                                }
                            }
                            return(Ok());
                        }
                        else
                        {
                            return(BadRequest("wait"));
                        }
                    }
                    else
                    {
                        return(BadRequest("bad time"));
                    }
                }
                else
                {
                    db.CreateRtRequest(newRtreq);

                    if (mSettings.SendNotificationToClient == true)
                    {
                        string sendResultMessage;
                        var    sendResult = mailSender.SendEMailMessageToClient(
                            newRtreq.Email,
                            mSettings.DefaultMessageToClient,
                            mSettings.Credentials_Name,
                            mSettings.Credentials_Pass,
                            mSettings.SmtpServer_Host,
                            mSettings.SmtpServer_Port,
                            out sendResultMessage);
                        if (sendResult != 1)
                        {
                            return(BadRequest(sendResultMessage));
                        }
                    }
                    if (mSettings.SendNotificationToHQ == true)
                    {
                        string sendResultMessage;
                        var    sendResult = mailSender.SendEMailMessageToHQ(
                            mSettings.HQeMail,
                            newRtreq,
                            mSettings.Credentials_Name,
                            mSettings.Credentials_Pass,
                            mSettings.SmtpServer_Host,
                            mSettings.SmtpServer_Port,
                            out sendResultMessage);
                        if (sendResult != 1)
                        {
                            return(BadRequest(sendResultMessage));
                        }
                    }

                    return(Ok(newRtreq));
                }
            }
            return(BadRequest(ModelState));
        }
Example #9
0
        public async Task <RtRequest> Get(string id)
        {
            RtRequest rtreq = await db.ReadRtRequestAsync(id);

            return(rtreq);
        }