Exemplo n.º 1
0
        public IHttpActionResult Post(Person person)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(this.ModelState);
            }

            return Created(this.context.AddPerson(person));
        }
        public Person AddPerson(Person person)
        {
            lock (this.persons)
            {
                person.Id = this.persons.Count == 0 ? 0 : this.persons.Max(p => p.Id) + 1;
                person.UpdateTime = DateTimeOffset.Now;
                this.persons.Add(person);
            }

            return person;
        }
Exemplo n.º 3
0
        private static void CsvServiceDemo()
        {
            Console.WriteLine("Csv demo");
            Console.WriteLine("Add new Person entity");
            var ctx = new Container(serviceRoot);
            var person = new Person() { Comment = "some comment" };
            ctx.AddToPeople(person);
            ctx.SaveChanges();
            Console.WriteLine("New person id is {0}", person.Id);

            string fileName = string.Format("person{0}.csv", person.Id);
            Console.WriteLine("Download the csv file {0}.", fileName);
            DownloadFile(ctx.People.ByKey(person.Id).GetPath(""), fileName, "text/csv");

            Console.WriteLine("Open the file");
            Process.Start(fileName);
        }
Exemplo n.º 4
0
        private static void VCardServiceDemo()
        {
            var ctx = new Container(serviceRoot);
            var person = new Person()
            {
                Card = new BusinessCard { ORG = "New Org", N = "LN2;FN1", FN = "LF2", Title = "New Title" }
            };

            ctx.AddToPeople(person);
            ctx.SaveChanges();
            Console.WriteLine("New person id is {0}", person.Id);

            string fileName = string.Format("person{0}_vcard.vcf", person.Id);
            Console.WriteLine("Download the csv file {0}.", fileName);
            DownloadFile(ctx.People.ByKey(person.Id).GetPath("Card"), fileName, "text/x-vCard");

            Console.WriteLine("Open the file");
            Process.Start(fileName);
        }