public IHttpActionResult PutSMUser(int id, SMUser sMUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sMUser.SMUserId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetSMUser(int id)
        {
            SMUser sMUser = db.Users.Find(id);

            if (sMUser == null)
            {
                return(NotFound());
            }

            return(Ok(sMUser));
        }
示例#3
0
        public SMUser GetUser(string userName, string password)
        {
            var    tbl  = ServiceProxy.GetUser(userName, password);
            SMUser user = null;

            if (tbl.Rows.Count != 0)
            {
                user = tbl.Rows[0].To <SMUser>();
            }
            return(user);
        }
        public IHttpActionResult PostSMUser(SMUser sMUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Users.Add(sMUser);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = sMUser.SMUserId }, sMUser));
        }
        public IHttpActionResult DeleteSMUser(int id)
        {
            SMUser sMUser = db.Users.Find(id);

            if (sMUser == null)
            {
                return(NotFound());
            }

            db.Users.Remove(sMUser);
            db.SaveChanges();

            return(Ok(sMUser));
        }
示例#6
0
        private void SignIn(SMUser user)
        {
            SessionManager.CurrentUser = user;
            var claims = new List <Claim>();

            claims.Add(new Claim(user.UserId, user.UserName));
            ClaimsIdentity identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            AuthManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = false,
                AllowRefresh = true,
                ExpiresUtc   = DateTime.Now.AddSeconds(15)
            }, identity);
        }