Пример #1
0
        // PUT api/Login/5
        public async Task<IHttpActionResult> PutUserInformation(int id, UserInformation userinformation)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
		public async Task<IHttpActionResult> GetUserInformations()
		{
			if (this.User == null)
			{
				return this.NotFound();
			}

			var userName = this.User.Identity.Name;

			var userInformation =
				await
					this.getFitContext.UserInformations
					.FirstOrDefaultAsync(
						information => information.UserName == userName);
			
			if (userInformation != null)
			{
				// todo: find better method around this
				var userDevices = this.getFitContext.UserDevices.Where(device => device.UserId == userInformation.Id);
				userInformation.UserDevices = await userDevices.ToListAsync();
				
				return this.Ok(userInformation);
			}
			
			var newUserInformation = new UserInformation
			{
				UserName = userName,
				UserDevices = new Collection<UserDevice>()
			};

			this.getFitContext.UserInformations.Add(newUserInformation);
			await this.getFitContext.SaveChangesAsync();
			return this.Ok(newUserInformation);
		}
Пример #3
0
        public async Task<IHttpActionResult> PostUserInformation(UserInformation userinformation)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.UserInformations.Add(userinformation);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = userinformation.Id }, userinformation);
        }