public IHttpActionResult PutCustomerV2(int id, CustomerV2 customerV2)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customerV2.Id)
            {
                return(BadRequest());
            }

            db.Entry(customerV2).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerV2Exists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetCustomerV2(int id)
        {
            CustomerV2 customerV2 = db.customerV2s.Find(id);

            if (customerV2 == null)
            {
                return(NotFound());
            }

            return(Ok(customerV2));
        }
        public IHttpActionResult PostCustomerV2(CustomerV2 customerV2)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.customerV2s.Add(customerV2);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = customerV2.Id }, customerV2));
        }
        public IHttpActionResult DeleteCustomerV2(int id)
        {
            CustomerV2 customerV2 = db.customerV2s.Find(id);

            if (customerV2 == null)
            {
                return(NotFound());
            }

            db.customerV2s.Remove(customerV2);
            db.SaveChanges();

            return(Ok(customerV2));
        }
        public async Task GivenIPostACustomerWithTheGivenNameV2(string givenName)
        {
            var customer = new CustomerV2();

            customer.GivenName  = givenName;
            customer.FamilyName = "Smith";
            await PostCustomer(customer, Constants.API_VERSION_2);

            _scenarioContext["CustomerId"] = await _assertionHelper.GetKeyFromResponse("CustomerId", _response);

            if (_response.IsSuccessStatusCode)
            {
                DeleteRowFromSql("dss-customers", "id", _scenarioContext["CustomerId"] as string);
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            string     fileNameV1 = @"e:\customer.v1.xml";
            string     fileNameV2 = @"e:\customer.v2.xml";
            CustomerV1 customerV1 = new CustomerV1
            {
                Name    = "张三",
                PhoneNo = "9999-99999999",
                Address = "江苏省 苏州市 星湖街 328号"
            };

            Serialize <CustomerV1>(customerV1, fileNameV1);
            CustomerV2 customerV2 = Deserialize <CustomerV2>(fileNameV1);

            Serialize <CustomerV2>(customerV2, fileNameV2);
        }
示例#7
0
        static void Main(string[] args)
        {
            string     fileName   = "customer.xml";
            CustomerV1 customerV1 = new CustomerV1
            {
                Name    = "张三",
                PhoneNo = "9999-99999999"
            };

            Console.WriteLine("CustomerV1");
            Console.WriteLine("\tName\t: {0}\n\tPhoneNo\t: {1}",
                              customerV1.Name, customerV1.PhoneNo);

            Serialize <CustomerV1>(customerV1, fileName);
            CustomerV2 customerV2 = Deserialize <CustomerV2>(fileName);

            Console.WriteLine("CustomerV2");
            Console.WriteLine("\tName\t: {0}\n\tPhoneNo\t: {1}\n\tAddress\t: {2}", customerV2.Name, customerV2.PhoneNo, customerV2.Address ?? "NIL");
        }