コード例 #1
0
        public async Task <IActionResult> AddUser([FromBody]  ApiModelUser userInfo)
        {
            if (ModelState.IsValid)
            {
                EmosUser emosUser = new EmosUser();

                emosUser.FirstName = userInfo.firstName;
                emosUser.LastName  = userInfo.lastName;
                //emosUser.Office = userInfo.office;
                //emosUser.Rank = userInfo.rank;
                //emosUser.Service = userInfo.service;
                //emosUser.Team = userInfo.team;
                //emosUser.BadgeCode = userInfo.badgeCode;
                await _appDbContext.AddAsync(emosUser);

                await _appDbContext.SaveChangesAsync();

                return(Ok(new ApiModelUser {
                    id = emosUser.Id, firstName = emosUser.FirstName, lastName = emosUser.LastName,                         /* office = emosUser.Office, rank = emosUser.Rank, service = emosUser.Service, team = emosUser.Team, badgeCode = emosUser.BadgeCode*/
                }));
            }
            // retrieve the user info
            //HttpContext.User
            //var userId = _caller.Claims.Single(c => c.Type == "id");
            return(BadRequest());
        }
コード例 #2
0
        public async Task <IActionResult> DeleteUser(int id)
        {
            if (ModelState.IsValid)
            {
                EmosUser user = await _appDbContext.EmosUsers.SingleOrDefaultAsync(u => u.Id == id);

                if (user != null)
                {
                    _appDbContext.Remove <EmosUser>(user);
                    await _appDbContext.SaveChangesAsync();

                    // retrieve the user info
                    //HttpContext.User
                    //var userId = _caller.Claims.Single(c => c.Type == "id");

                    return(new NoContentResult());
                }
                else
                {
                    return(NotFound());
                }
            }

            return(BadRequest());
        }
コード例 #3
0
        public async Task <IActionResult> UpdateUser([FromBody] ApiModelUser userInfo)
        {
            if (ModelState.IsValid)
            {
                EmosUser user = await _appDbContext.EmosUsers.SingleOrDefaultAsync(u => u.Id == userInfo.id);

                if (user != null)
                {
                    user.FirstName = userInfo.firstName;
                    user.LastName  = userInfo.lastName;
                    //user.Office = userInfo.office;
                    //user.Grade = userInfo.;
                    //user.Service = userInfo.service;
                    //user.Team = userInfo.team;
                    user.CardCode = userInfo.badgeCode;
                    await _appDbContext.SaveChangesAsync();

                    // retrieve the user info
                    //HttpContext.User
                    //var userId = _caller.Claims.Single(c => c.Type == "id");

                    return(Ok(new ApiModelUser {
                        id = user.Id, firstName = user.FirstName, lastName = user.LastName, /* office = user.Office, rank = user.Rank, service = user.Service, team = user.Team,*/ badgeCode = user.CardCode
                    }));
                }
            }

            return(BadRequest());
        }