コード例 #1
0
        // PUT api/Default1/5
        public async Task<IHttpActionResult> PutUserModel(int id, UserModel usermodel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
        public async Task<IHttpActionResult> Register(UserModel userModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            UserModel result = await repository.RegisterUserAsync(userModel);

            return Ok();
        }
コード例 #3
0
        public async Task<IHttpActionResult> PostUserModel(UserModel usermodel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Users.Add(usermodel);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = usermodel.Id }, usermodel);
        }
コード例 #4
0
 public async Task<UserModel> RegisterUserAsync(UserModel userModel)
 {
     ctx.Users.Add(userModel);
     await ctx.SaveChangesAsync();
     return userModel;
 }
コード例 #5
0
 public async Task<UserModel> FindUser(string userName, string password)
 {
     UserModel userModel=new UserModel{Password=password,UserName=userName,ConfirmPassword=password};
     var user = ctx.Users.Where(a => a.UserName == userName && a.Password == password).FirstOrDefault();
     return user;
 }