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."));
        }
        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 #3
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 #4
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."));
        }