Ejemplo n.º 1
0
        public IActionResult Login([FromBody] DataViewModel dmm)
        {
            DataViewModel dm = new DataViewModel();

            try
            {
                dm.checkresult = _notification.Authenticate(dmm.username, dmm.password);
                if (dm.checkresult == false)
                {
                    /*using (var channel = conn.CreateModel())
                     * {
                     *  channel.QueueDeclare(queue: "notification",
                     *                       durable: false,
                     *                       exclusive: false,
                     *                       autoDelete: false,
                     *                       arguments: null);
                     *
                     *  string message = "User: "******" with this Password: "******"is Failed";
                     *  var body = Encoding.UTF8.GetBytes(message);
                     *
                     *  channel.BasicPublish(exchange: "",
                     *                       routingKey: "notification",
                     *                       basicProperties: null,
                     *                           body: body);
                     * }*/
                    dm.messages   = "Your Data has not been submitted successfully.";
                    dm.statusCode = System.Net.HttpStatusCode.OK;
                }
                else
                {
                    using (var channel = conn.CreateModel())
                    {
                        channel.QueueDeclare(queue: "notification",
                                             durable: false,
                                             exclusive: false,
                                             autoDelete: false,
                                             arguments: null);

                        string message = "User: "******" with this Password: "******"is success";
                        var    body    = Encoding.UTF8.GetBytes(message);

                        channel.BasicPublish(exchange: "",
                                             routingKey: "notification",
                                             basicProperties: null,
                                             body: body);
                    }
                    dm.messages   = "Your Data has been submitted.You will be notified of the response in 1 minute";
                    dm.statusCode = System.Net.HttpStatusCode.OK;
                }
            }
            catch (Exception e)
            {
                dm.statusCode = System.Net.HttpStatusCode.BadRequest;
            }
            Console.WriteLine(dm);

            return(new ObjectResult(dm));
        }