Example #1
0
        public ITestActionResult Patch(int key, [FromBody] Delta <ETagsCustomer> patch, ODataQueryOptions <ETagsCustomer> queryOptions)
        {
            IEnumerable <ETagsCustomer> appliedCustomers = customers.Where(c => c.Id == key);

            if (appliedCustomers.Count() == 0)
            {
                return(BadRequest(string.Format("The entry with Id {0} doesn't exist", key)));
            }

            if (queryOptions.IfMatch != null)
            {
                IQueryable <ETagsCustomer> ifMatchCustomers = queryOptions.IfMatch.ApplyTo(appliedCustomers.AsQueryable()).Cast <ETagsCustomer>();

                if (ifMatchCustomers.Count() == 0)
                {
                    return(StatusCode(HttpStatusCode.PreconditionFailed));
                }
            }

            ETagsCustomer customer = appliedCustomers.Single();

            patch.Patch(customer);

            return(Ok(customer));
        }
Example #2
0
        internal static ETagsDerivedCustomer CreateDerivedCustomer(ETagsCustomer customer)
        {
            ETagsDerivedCustomer newCustomer = new ETagsDerivedCustomer();

            newCustomer.Id   = customer.Id;
            newCustomer.Role = customer.Name + customer.Id;
            ReplaceCustomer(newCustomer, customer);
            return(newCustomer);
        }
Example #3
0
        internal static bool ValidateEtag(ETagsCustomer customer, ODataQueryOptions options)
        {
            if (options.IfMatch != null)
            {
                IQueryable <ETagsCustomer> ifMatchCustomers = options.IfMatch.ApplyTo((new ETagsCustomer[] { customer }).AsQueryable()).Cast <ETagsCustomer>();

                if (ifMatchCustomers.Count() == 0)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #4
0
        public ITestActionResult Put(int key, [FromBody] ETagsCustomer eTagsCustomer, ODataQueryOptions <ETagsCustomer> queryOptions)
        {
            if (key != eTagsCustomer.Id)
            {
                return(BadRequest("The Id of customer is not matched with the key"));
            }

            IEnumerable <ETagsCustomer> appliedCustomers = customers.Where(c => c.Id == eTagsCustomer.Id);

            if (appliedCustomers.Count() == 0)
            {
                customers.Add(eTagsCustomer);
                return(Ok(eTagsCustomer));
            }

            if (queryOptions.IfMatch != null)
            {
                IQueryable <ETagsCustomer> ifMatchCustomers = queryOptions.IfMatch.ApplyTo(appliedCustomers.AsQueryable()).Cast <ETagsCustomer>();

                if (ifMatchCustomers.Count() == 0)
                {
                    return(StatusCode(HttpStatusCode.PreconditionFailed));
                }
            }

            ETagsCustomer customer = appliedCustomers.Single();

            customer.Name                   = eTagsCustomer.Name;
            customer.Notes                  = eTagsCustomer.Notes;
            customer.BoolProperty           = eTagsCustomer.BoolProperty;
            customer.ByteProperty           = eTagsCustomer.ByteProperty;
            customer.CharProperty           = eTagsCustomer.CharProperty;
            customer.DecimalProperty        = eTagsCustomer.DecimalProperty;
            customer.DoubleProperty         = eTagsCustomer.DoubleProperty;
            customer.ShortProperty          = eTagsCustomer.ShortProperty;
            customer.LongProperty           = eTagsCustomer.LongProperty;
            customer.SbyteProperty          = eTagsCustomer.SbyteProperty;
            customer.FloatProperty          = eTagsCustomer.FloatProperty;
            customer.UshortProperty         = eTagsCustomer.UshortProperty;
            customer.UintProperty           = eTagsCustomer.UintProperty;
            customer.UlongProperty          = eTagsCustomer.UlongProperty;
            customer.GuidProperty           = eTagsCustomer.GuidProperty;
            customer.DateTimeOffsetProperty = eTagsCustomer.DateTimeOffsetProperty;

            return(Ok(customer));
        }
Example #5
0
 internal static void ReplaceCustomer(ETagsCustomer newCustomer, ETagsCustomer customer)
 {
     newCustomer.Name                   = customer.Name;
     newCustomer.Notes                  = customer.Notes;
     newCustomer.BoolProperty           = customer.BoolProperty;
     newCustomer.ByteProperty           = customer.ByteProperty;
     newCustomer.CharProperty           = customer.CharProperty;
     newCustomer.DecimalProperty        = customer.DecimalProperty;
     newCustomer.DoubleProperty         = customer.DoubleProperty;
     newCustomer.ShortProperty          = customer.ShortProperty;
     newCustomer.LongProperty           = customer.LongProperty;
     newCustomer.SbyteProperty          = customer.SbyteProperty;
     newCustomer.FloatProperty          = customer.FloatProperty;
     newCustomer.UshortProperty         = customer.UshortProperty;
     newCustomer.UintProperty           = customer.UintProperty;
     newCustomer.UlongProperty          = customer.UlongProperty;
     newCustomer.GuidProperty           = customer.GuidProperty;
     newCustomer.DateTimeOffsetProperty = customer.DateTimeOffsetProperty;
 }