示例#1
0
        public IHttpActionResult Patch(int key, 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));
        }
示例#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);
        }
示例#3
0
        public IHttpActionResult Put(int key, 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);

            return(ApplyPut(eTagsCustomer, appliedCustomers.Single(), queryOptions));
        }
示例#4
0
        public IHttpActionResult ApplyPut(ETagsCustomer eTagsCustomer, ETagsCustomer original, ODataQueryOptions <ETagsCustomer> queryOptions)
        {
            if (!Helpers.ValidateEtag(original, queryOptions))
            {
                return(StatusCode(HttpStatusCode.PreconditionFailed));
            }

            Helpers.ReplaceCustomer(original, eTagsCustomer);

            return(Ok(original));
        }
示例#5
0
        internal IHttpActionResult ApplyPatch(Delta <ETagsCustomer> patch, ETagsCustomer original, ODataQueryOptions queryOptions)
        {
            if (!Helpers.ValidateEtag(original, queryOptions))
            {
                return(StatusCode(HttpStatusCode.PreconditionFailed));
            }

            patch.Patch(original);

            return(Ok(original));
        }
示例#6
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);
        }
示例#7
0
        public IHttpActionResult Put(int key, 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));
        }
示例#8
0
        public IHttpActionResult Put(int key, 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);
        }
示例#9
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;
 }
示例#10
0
 public IHttpActionResult PutContainedCustomer(ETagsCustomer eTagsCustomer, ODataQueryOptions <ETagsCustomer> queryOptions)
 {
     return(ApplyPut(eTagsCustomer, customer.ContainedCustomer, queryOptions));
 }