예제 #1
0
        public IActionResult UpdateCarpet([FromRoute] string username, [FromRoute] int id)
        {
            var carpet = _context
                         .Carpets
                         .FirstOrDefault(entity => entity.Username == username && entity.Id == id && !entity.Removed);

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

            var lastStripe = _context
                             .Stripes
                             .Where(entity => entity.CarpetId == id)
                             .OrderByDescending(entity => entity.Ordinal)
                             .FirstOrDefault();

            var stripe = new StripeEntity
            {
                CarpetId    = id,
                ColorString = StripeEntity.DefaultColor,
                Height      = 10.0,
                Ordinal     = lastStripe?.Ordinal + 1 ?? 0
            };

            _context
            .Stripes
            .Add(stripe);

            _context.SaveChanges();

            return(Ok(stripe));
        }
예제 #2
0
        public void FromJsonAutoNoObject()
        {
            var json = "{\"id\": \"ch_123\"}";

            var o = StripeEntity.FromJson(json);

            Assert.Null(o);
        }
예제 #3
0
        public void FromJsonAutoUnknownObject()
        {
            var json = "{\"id\": \"ch_123\", \"object\": \"foo\"}";

            var o = StripeEntity.FromJson(json);

            Assert.Null(o);
        }
예제 #4
0
        public void FromJsonGeneric()
        {
            var json = "{\"integer\": 234, \"string\": \"String!\"}";

            var o = StripeEntity.FromJson <TestEntity>(json);

            Assert.NotNull(o);
            Assert.Equal(234, o.Integer);
            Assert.Equal("String!", o.String);
        }
예제 #5
0
        public void FromJsonAuto()
        {
            var json = "{\"id\": \"ch_123\", \"object\": \"charge\"}";

            var o = StripeEntity.FromJson(json);

            Assert.NotNull(o);
            Assert.IsType <Charge>(o);
            Assert.Equal("ch_123", ((Charge)o).Id);
        }
        private static bool IsExistingCustomer(string email)
        {
            var options = new CustomerListOptions
            {
                Email = "*****@*****.**",
                Limit = 1
            };
            var service = new CustomerService();
            StripeList <Customer> customers = service.List(
                options
                );
            StripeEntity <Customer> customer = service.Get(email);

            return(false);
        }
예제 #7
0
        private static T ProcessResponse <T>(StripeResponse response)
            where T : IStripeEntity
        {
            if (response.StatusCode != HttpStatusCode.Created)
            {
                throw BuildStripeException(response);
            }

            T obj;

            try
            {
                obj = StripeEntity.FromJson <T>(response.Content);
            }
            catch (Newtonsoft.Json.JsonException)
            {
                throw BuildInvalidResponseException(response);
            }

            obj.StripeResponse = response;

            return(obj);
        }