Example #1
0
        public MainModule()
        {
            Get["/"] = x =>
            {
                var repo = new PersonRepository();
                var persons = repo.GetAll();
                return Response.AsJson(persons);
            };

            //Post["/"] = x =>
            //{
            //    var person = this.Bind<Person>();
            //    var repo = new PersonRepository();
            //    if (!repo.Exists(person.Name))
            //    {
            //        Console.WriteLine("Person with name {0} was added", person.Name);
            //        repo.Add(person);
            //    }
            //    else
            //    {
            //        Console.WriteLine("Person with name {0} already exists", person.Name);
            //    }

            //    return (Response)"OK";
            //};

            Post["/", true] = async (x, ct) =>
            {
                var person = this.Bind<Person>();
                var envelope = new ConsistentHashableEnvelope(person,person.Name);
                var result = await AkkaUtil.PersonPostActor.Ask<string>(envelope);
                return (Response) result;

            };
        }
        public PersonPostActor()
        {
            Receive<Person>(person =>
            {
                var repo = new PersonRepository();
                if (!repo.Exists(person.Name))
                {
                    Console.WriteLine("Person with name {0} was added", person.Name);
                    repo.Add(person);
                }
                else
                {
                    Console.WriteLine("Person with name {0} already exists", person.Name);
                }

                Sender.Tell("OK");
            });
        }