// PUT: odata/Notes(5)
        public async Task<IHttpActionResult> Put([FromODataUri] Guid key, Delta<Note> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Note note = await db.Notes.FindAsync(key);
            if (note == null)
            {
                return NotFound();
            }

            patch.Put(note);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NoteExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(note);
        }
示例#2
0
        // PUT: odata/Students(5)
        public async Task<IHttpActionResult> Put([FromODataUri] int key, Delta<Student> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Student student = await db.Students.FindAsync(key);
            if (student == null)
            {
                return NotFound();
            }

            patch.Put(student);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(student);
        }
        // PUT: odata/Customers(5)
        public async Task<IHttpActionResult> Put([FromODataUri] int key, Delta<Customer> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var customer = await _db.Customers.FindAsync(key);
            if (customer == null)
            {
                return NotFound();
            }

            patch.Put(customer);

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(key))
                {
                    return NotFound();
                }
                throw;
            }

            return Updated(customer);
        }
        // PUT: odata/PlatformsImporter(5)
        public async Task<IHttpActionResult> Put([FromODataUri] string key, Delta<Platform> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Platform platform = await db.Platforms.FindAsync(key);
            if (platform == null)
            {
                return NotFound();
            }

            patch.Put(platform);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlatformExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(platform);
        }
		// PUT: odata/Users(5)
		public async Task<IHttpActionResult> Put( [FromODataUri] int key, Delta<Account> patch )
		{
			Validate( patch.GetEntity() );

			if ( !ModelState.IsValid )
			{
				return BadRequest( ModelState );
			}

			var user = await _db.Accounts.SingleOrDefaultAsync( u => u.Id == key );
			if ( user == null )
			{
				return NotFound();
			}

			patch.Put( user );

			try
			{
				await _db.SaveChangesAsync();
			}
			catch ( DbUpdateConcurrencyException )
			{
				if ( !ApplicationUserExists( key ) )
				{
					return NotFound();
				}
				else
				{
					throw;
				}
			}

			return Updated( user );
		}
示例#6
0
        // PUT: odata/Person(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta<Person> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Person person = db.People.Find(key);
            if (person == null)
            {
                return NotFound();
            }

            patch.Put(person);

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

            return Updated(person);
        }
        // PUT: odata/OptionSetEntities(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta<OptionSetEntity> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            OptionSetEntity optionSetEntity = db.OptionSetEntities.Find(key);
            if (optionSetEntity == null)
            {
                return NotFound();
            }

            patch.Put(optionSetEntity);

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

            return Updated(optionSetEntity);
        }
        public IHttpActionResult PutToAddress(int key, Delta<OpenAddress> address)
        {
            IList<OpenCustomer> customers = CreateCustomers();
            OpenCustomer customer = customers.FirstOrDefault(c => c.CustomerId == key);
            if (customer == null)
            {
                return NotFound();
            }

            // Verify the origin address
            OpenAddress origin = customer.Address;
            VerifyOriginAddress(key, origin);

            address.Put(origin); // Do put

            // Verify the put address
            Assert.Equal("UpdatedStreet", origin.Street);
            Assert.Equal("UpdatedCity", origin.City);

            Assert.NotNull(origin.DynamicProperties);
            KeyValuePair<string, object> dynamicProperty = Assert.Single(origin.DynamicProperties); // only one
            Assert.Equal("Publish", dynamicProperty.Key);
            Assert.Equal(new Date(2016, 2, 2), dynamicProperty.Value);

            return Updated(customer);
        }
        // PUT: odata/ResidentViewModels(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta<Contracts.IResident> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Contracts.IResident residentViewModel = db.GetAllResidents().Where(r => r.Id == key).FirstOrDefault();
            if (residentViewModel == null)
            {
                return NotFound();
            }

            patch.Put(residentViewModel);

            //try
            //{
            //    db.EditRoom(residentViewModel);
            //}
            //catch (DbUpdateConcurrencyException)
            //{
            //    if (!ResidentViewModelExists(key))
            //    {
            //        return NotFound();
            //    }
            //    else
            //    {
            //        throw;
            //    }
            //}

            return Updated(residentViewModel);
        }
        public IHttpActionResult PutToCurrentShapeOfCircle(int key, Delta<Circle> shape)
        {
            Window window = _windows.FirstOrDefault(e => e.Id == key);
            if (window == null)
            {
                return NotFound();
            }

            Circle origin = window.CurrentShape as Circle;
            if (origin == null)
            {
                return NotFound();
            }

            shape.Put(origin);
            return Ok(origin);
        }
        public IHttpActionResult PutToAddress(int key, Delta<Address> address)
        {
            Account account = Accounts.FirstOrDefault(a => a.Id == key);
            if (account == null)
            {
                return NotFound();
            }

            if (account.Address == null)
            {
                account.Address = new Address();
            }

            address.Put(account.Address);

            return Updated(account);
        }
示例#12
0
        // PUT: odata/Players(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta<Player> delta)
        {
            Validate(delta.GetEntity());

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            // TODO: Get the entity here.
            var player = (from p in _cricketContext.Players
                          where p.Id == key
                          select p).First();

            delta.Put(player);

            // TODO: Save the patched entity.

            // return Updated(player);
            return StatusCode(HttpStatusCode.NotImplemented);
        }
        // PUT: odata/IMEI(5)
        public async Task<IHttpActionResult> Put([FromODataUri] int key, Delta<IMEIToCallsign> patch)
        {
            var imeiToCallsign = await _imeiService.GetFromId(key);
            if (imeiToCallsign == null)
            {
                return NotFound();
            }

            patch.Put(imeiToCallsign);

            Validate(imeiToCallsign);

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            await _imeiService.RegisterCallsign(imeiToCallsign.IMEI, imeiToCallsign.CallSign, imeiToCallsign.Type);

            var newIMEI = await _imeiService.GetFromIMEI(imeiToCallsign.IMEI);

            await _logService.LogIMEIRegistered(User.Identity.GetUserName(), newIMEI.IMEI, newIMEI.CallSign, newIMEI.Type);

            return Updated(newIMEI);
        }