예제 #1
0
        public ActionResult Login(UserViewModel user, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (IsValid(user))
                {
                    var userRoles = userModel.GetUser(user.UserName).Roles.Select(role => AutoMapper.Mapper.Map <Role>(role));
                    foreach (var role in userRoles)
                    {
                        if (!Roles.IsUserInRole(user.UserName, role.ToString()))
                        {
                            Roles.AddUserToRole(user.UserName, role.ToString());
                        }
                    }

                    FormsAuthentication.SetAuthCookie(user.UserName, false);
                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError("", "Login data is incorrect!");
                }
            }
            return(View(user));
        }
예제 #2
0
        // GET: api/User/UserName
        public IHttpActionResult Get(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            var user = AutoMapper.Mapper.Map <User>(userModel.GetUser(id));

            if (user == null)
            {
                return(NotFound());
            }
            return(Ok(user));
        }
예제 #3
0
 public async Task <ActionResult <string> > GetUser(int id)
 {
     Console.WriteLine("GetUser");
     return(userModel.GetUser(id));
 }
예제 #4
0
 public async Task <ActionResult <string> > GetUser(int id)
 {
     return(_context.GetUser(id));
 }