Beispiel #1
0
        public async Task <IActionResult> PostAsync([FromBody] string value)
        {
            string serializedOrder = JsonConvert.SerializeObject(value);

            Console.WriteLine("========");
            Console.WriteLine("Info: DepartmentsController => Post => Recieved a new deparment details:");
            Console.WriteLine(serializedOrder);
            Console.WriteLine("=========");
            Dept newDept;

            using (var db = new IshaMasterContext())
            {
                newDept          = new Dept();
                newDept.DeptName = value;
                db.Dept.Add(newDept);
                var count = db.SaveChanges();
            }

            var message = new StringBuilder();

            message.Append("{ \n event: \n DepartmentCreated \n entity: Department \n value:{ \n");
            message.Append(" ID: ");
            message.Append(newDept.DeptId);
            message.Append(",\n Name: ");
            message.Append(serializedOrder);
            message.Append("\n} \n }");

            var producer = new ProducerWrapper(this._config, "DepartmentCreated");
            await producer.writeMessage(message.ToString());

            return(Created(Url.RouteUrl(newDept.DeptId), "Your deparment " + newDept.DeptId + " is created."));
        }
Beispiel #2
0
        public async Task <IActionResult> CreateAsync(Raporlar rapor)
        {
            if (ModelState.IsValid)
            {
                try {
                    using (var db = new setur_databaseContext())
                    {
                        await db.Raporlars.AddAsync(rapor);

                        await db.SaveChangesAsync();

                        // Kafkaya rapor hazirlama islemini bildir
                        string serializedOrder = JsonConvert.SerializeObject(rapor);

                        var producer = new ProducerWrapper(this.config, "raporrequests");
                        await producer.writeMessage(serializedOrder);

                        return(Ok(rapor));
                    }
                }
                catch (Exception ex) {
                    return(BadRequest(ex));
                }
            }

            return(BadRequest(ModelState));
        }
Beispiel #3
0
        public async Task <KafkaProcesStatus> ProcessFeedFile()
        {
            var config = new ProducerConfig
            {
                BootstrapServers = "localhost:9092"
            };
            //var response = new DeliveryResult<string, string>();
            var feedFileRecords = getFileDetails.GetFileDetails();

            if (feedFileRecords != null)
            {
                try
                {
                    foreach (Profile record in feedFileRecords)
                    {
                        var    producer        = new ProducerWrapper(config, "kafkaservice");
                        string serializedOrder = JsonConvert.SerializeObject(record);
                        /* response =*/
                        await producer.writeMessage(serializedOrder);
                    }
                    getFileDetails.FeedFileRemove();
                }
                catch (Exception e)
                {
                }
            }
            //if(response.Status.ToString().Equals("Persisted"))
            //{
            //    return KafkaProcesStatus.completed;
            //}
            return(KafkaProcesStatus.error);
        }
        public async Task <IActionResult> PostAsync([FromBody] Vendor value)
        {
            string serializedOrder = JsonConvert.SerializeObject(value);

            Console.WriteLine("========");
            Console.WriteLine("Info: DepartmentUserController => Post => Recieved a new vendor details:");
            Console.WriteLine(serializedOrder);
            Console.WriteLine("=========");
            Vendor newVendor;

            using (var db = new IshaMasterContext())
            {
                newVendor = new Vendor(value);
                db.Vendor.Add(newVendor);
                var count = db.SaveChanges();
            }

            var message = new StringBuilder();

            message.Append("{ \n event: \n VendorRequested \n entity: vendor \n value:{ \n");
            message.Append(" ID: ");
            message.Append(newVendor.ID);
            message.Append(",\n details: ");
            message.Append(serializedOrder);
            message.Append("\n} \n }");

            var producer = new ProducerWrapper(this._config, "VendorRequested");
            await producer.writeMessage(message.ToString());

            return(Created(Url.RouteUrl(newVendor.ID), "Your Vendor " + newVendor.Name + " with mobile number " + newVendor.MobileNumber + " is created."));
        }
Beispiel #5
0
 public async Task Handle(CupcakeOrderPackagedEvent boxedEvent,CancellationToken cancellationToken)
 {
    Console.WriteLine($"Hanlding event - {nameof(CupcakeOrderPackagedEvent)} ");
    //Serialize 
     string serializedOrder = JsonConvert.SerializeObject(boxedEvent.Order);
     var producer = new ProducerWrapper(this._config,"readytoship");
     await producer.writeMessage(serializedOrder);
 }
Beispiel #6
0
 public async Task Handle(CupcakeNewOrderRecievedEvent newOrderEvent,CancellationToken cancellationToken)
 {
    Console.WriteLine($"Hanlding event - {nameof(CupcakeNewOrderRecievedEvent)} ");
    //Serialize 
     string serializedOrder = JsonConvert.SerializeObject(newOrderEvent.Order);
     var producer = new ProducerWrapper(this._config,"orderrequests");
     await producer.writeMessage(serializedOrder);
 }
        public async Task <Client> save([FromBody] Client client)
        {
            CatalogueRepository.Clients.Add(client);
            CatalogueRepository.SaveChanges();

            string serializedClient = JsonSerializer.Serialize(client);

            Console.WriteLine("========");
            Console.WriteLine("Info: ClientController => Post => send a new client to kafka:");
            Console.WriteLine(serializedClient);
            Console.WriteLine("=========");

            var producer = new ProducerWrapper("clients");
            await producer.writeMessage(serializedClient);

            return(client);
        }
Beispiel #8
0
        public async Task <IActionResult> ReportOrderFailureAsync([FromBody] ReportOrderFailureCommand cmd)
        {
            if (!ModelState.IsValid)
            {
                BadRequest();
            }

            var failedOrder = cmd.Order;

            Console.WriteLine("===============Recieved Failure Order====================");
            //TODO: Add command handler and raise event to capture this in the system.
            //Serialize
            string serializedOrder = JsonConvert.SerializeObject(failedOrder);
            var    producer        = new ProducerWrapper(this._config, "orderfailures");
            await producer.writeMessage(serializedOrder);

            return(Ok());
        }
        public async Task <ActionResult> PostAsync([FromBody] OrderRequest value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Serialize
            string serializedOrder = JsonConvert.SerializeObject(value);

            Console.WriteLine("========");
            Console.WriteLine("Info: OrderController => Post => Recieved a new purchase order:");
            Console.WriteLine(serializedOrder);
            Console.WriteLine("=========");

            var producer = new ProducerWrapper(this.config, "orderrequests");
            await producer.writeMessage(serializedOrder);

            return(Created("TransactionId", "Your order is in progress"));
        }
Beispiel #10
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] string value)
        {
            string serializedOrder = JsonConvert.SerializeObject(value);

            Console.WriteLine("========");
            Console.WriteLine("Info: DepartmentsController => Update => Recieved a updated deparment details:");
            Console.WriteLine(serializedOrder);
            Console.WriteLine("=========");


            using (var db = new IshaMasterContext())
            {
                Dept dept = db.Dept.FirstOrDefault(d => d.DeptId == id);
                if (dept == null)
                {
                    return(NotFound());
                }
                else
                {
                    dept.DeptName = value;
                    db.Dept.Update(dept);
                    var count = db.SaveChanges();
                    // return Ok();
                }
            }

            var message = new StringBuilder();

            message.Append("{ \n event: \n DepartmentUpdated \n entity: Department \n value: { \n");
            message.Append(" ID: ");
            message.Append(id);
            message.Append(",\n Name: ");
            message.Append(serializedOrder);
            message.Append("\n} }");

            var producer = new ProducerWrapper(this._config, "DepartmentUpdated");
            await producer.writeMessage(message.ToString());

            return(Created("departmentId", "Your deparment " + id + " is updated."));
        }
Beispiel #11
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Console.WriteLine("OrderProcessing Service Started");

            while (!stoppingToken.IsCancellationRequested)
            {
                var    consumerHelper = new ConsumerWrapper(consumerConfig, "orderrequests");
                string orderRequest   = consumerHelper.readMessage();

                //Deserilaize
                OrderRequest order = JsonConvert.DeserializeObject <OrderRequest>(orderRequest);

                //TODO:: Process Order
                Console.WriteLine($"Info: OrderHandler => Processing the order for {order.productname}");
                order.status = OrderStatus.COMPLETED;

                //Write to ReadyToShip Queue

                var producerWrapper = new ProducerWrapper(producerConfig, "orderrequests");
                await producerWrapper.writeMessage(JsonConvert.SerializeObject(order));
            }
        }
Beispiel #12
0
        public async Task <IActionResult> DeleteAsync(int id)
        {
            string serializedOrder = JsonConvert.SerializeObject(id);

            Console.WriteLine("========");
            Console.WriteLine("Info: DepartmentsController => Deleted => Recieved a deleted deparment details:");
            Console.WriteLine(serializedOrder);
            Console.WriteLine("=========");
            Dept          dept;
            StringBuilder message = new StringBuilder();

            using (var db = new IshaMasterContext())
            {
                dept = db.Dept.FirstOrDefault(d => d.DeptId == id);
                if (dept == null)
                {
                    message.Append("{ \n event: \n DepartmentDeleted \n entity: Department \n value: \n");
                    message.Append("Department record not found");
                    message.Append("\n }");
                }
                else
                {
                    db.Dept.Remove(dept);
                    var count = db.SaveChanges();
                    message = new StringBuilder();
                    message.Append("{ \n event: \n DepartmentDeleted \n entity: Department \n value: { \n");
                    message.Append(" ID: ");
                    message.Append(id);
                    message.Append(",\n Name: ");
                    message.Append(dept.DeptName);
                    message.Append("\n} \n }");
                }
            }

            var producer = new ProducerWrapper(this._config, "DepartmentDeleted");
            await producer.writeMessage(message.ToString());

            return(Created("departmentId", "Your deparment " + id + " is deleted."));
        }