public StatusCodeResult EmailEvent([FromBody] Object json)
        {
            try
            {
                //converting json to object
                var emailEvent = new EmailEvent(json.ToString());

                //Validate XML
                var xmlResponse = XsdValidation.XmlObjectValidation(emailEvent);

                if (xmlResponse != null)
                {
                    using (var connection = factory.CreateConnection())
                        using (var channel = connection.CreateModel())
                        {
                            var addUserBody = Encoding.UTF8.GetBytes(xmlResponse);
                            var properties  = channel.CreateBasicProperties();
                            properties.Headers = new Dictionary <string, object>();
                            properties.Headers.Add("eventType", "frontend.email_event");
                            channel.BasicPublish(exchange: "events.exchange",
                                                 routingKey: "",
                                                 basicProperties: properties,
                                                 body: addUserBody
                                                 );
                        }
                }
                return(StatusCode(201));
            }
            catch (Exception ex) {
                Sender.SendErrorMessage(ex);
                return(StatusCode(500));
            }
        }
        public async Task <StatusCodeResult> RequestInvoiceAsync([FromBody] object json)
        {
            try
            {
                //convert json to addUser object
                var requestInvoiceEntity = new RequestInvoiceFromFrontend(json.ToString());

                //Make the call for the UUID
                string responseBody = null;
                var    url          = "http://192.168.1.2/uuid-master/uuids/frontend/" + requestInvoiceEntity.UserId;
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Get, url))
                    {
                        using (var response = await client
                                              .SendAsync(request, HttpCompletionOption.ResponseHeadersRead)
                                              .ConfigureAwait(false))
                        {
                            response.EnsureSuccessStatusCode();
                            responseBody = await response.Content.ReadAsStringAsync();
                        }
                    }

                //Convert the response from json to dictionary
                var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(responseBody);

                //add response to addUserEntity uuid
                requestInvoiceEntity.uuid = values["uuid"];

                //Validate XML
                var xml = XsdValidation.XmlObjectValidation(requestInvoiceEntity);

                //when no errors send the message to rabbitmq
                if (xml != null)
                {
                    using (var connection = factory.CreateConnection())
                        using (var channel = connection.CreateModel())
                        {
                            var addUserBody = Encoding.UTF8.GetBytes(xml);
                            var properties  = channel.CreateBasicProperties();
                            properties.Headers = new Dictionary <string, object>();
                            properties.Headers.Add("eventType", "frontend.email_invoice");
                            channel.BasicPublish(exchange: "events.exchange",
                                                 routingKey: "",
                                                 basicProperties: properties,
                                                 body: addUserBody
                                                 );

                            SendLogToLogExchange(" request invoice");
                        }
                }
            }
            catch (Exception ex)
            {
                Sender.SendErrorMessage(ex);
                return(StatusCode(500));
            }

            return(StatusCode(201));
        }
        private void SendLogToLogExchange(string action)
        {
            //make log file entity
            Log log = new Log("Frontend " + action);

            //Validate XML
            var xml = XsdValidation.XmlObjectValidation(log);

            //when no errors send the message to rabbitmq
            if (xml != null)
            {
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        var addUserBody = Encoding.UTF8.GetBytes(xml);
                        channel.BasicPublish(exchange: "logs.exchange",
                                             routingKey: "",
                                             body: addUserBody
                                             );
                    }
            }
        }
        public async Task <StatusCodeResult> AddUserAsync([FromBody] Object json)
        {
            try
            {
                //convert json to addUser object
                var addUserEntity = new AddUserFromFrontend(json.ToString());

                //Create body for requesting UUID for the addUser object
                var body = new Dictionary <string, string>();
                body.Add("frontend", addUserEntity.UserId.ToString());

                //Make the call for the UUID
                // https://johnthiriet.com/efficient-post-calls/
                string responseBody = null;
                using (var client = new HttpClient())
                    using (var request = new HttpRequestMessage(HttpMethod.Post, "http://192.168.1.2/uuid-master/uuids"))
                        using (var httpContent = CreateHttpContent(body))
                        {
                            request.Content = httpContent;

                            using (var response = await client
                                                  .SendAsync(request, HttpCompletionOption.ResponseHeadersRead)
                                                  .ConfigureAwait(false))
                            {
                                response.EnsureSuccessStatusCode();
                                responseBody = await response.Content.ReadAsStringAsync();
                            }
                        }

                //Convert the response from json to dictionary
                var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(responseBody);

                //add response to addUserEntity uuid
                addUserEntity.uuid             = values["uuid"];
                addUserEntity.application_name = "frontend";

                //Validate XML
                var xml = XsdValidation.XmlObjectValidation(addUserEntity);

                //when no errors send the message to rabbitmq
                if (xml != null)
                {
                    using (var connection = factory.CreateConnection())
                        using (var channel = connection.CreateModel())
                        {
                            var addUserBody = Encoding.UTF8.GetBytes(xml);
                            var properties  = channel.CreateBasicProperties();
                            properties.Headers = new Dictionary <string, object>();
                            properties.Headers.Add("eventType", "frontend.add_user");
                            channel.BasicPublish(exchange: "events.exchange",
                                                 routingKey: "",
                                                 basicProperties: properties,
                                                 body: addUserBody
                                                 );

                            SendLogToLogExchange(" added a user from frontend");
                        }
                }
                return(StatusCode(201));
            }
            catch (Exception ex) {
                Sender.SendErrorMessage(ex);
                return(StatusCode(500));
            }
        }