示例#1
0
        public IHttpActionResult Login(UserLoginRequest model)
        {
            Response <User> response = new Response <User>
            {
                IsSuccess = false,
            };

            try
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        IQueryable <User> queryable = context.Set <User>().Where(c => c.Email == model.Email && c.Password == model.Password && c.Active == true).AsNoTracking();
                        queryable = queryable.Include <User, object>(c => c.Role);
                        User myUser = queryable.FirstOrDefault();

                        if (myUser != null)
                        {
                            myUser.Role.ClaimActions = context.Set <ClaimAction>().Where(c => c.RoleId == myUser.RoleId).ToList();
                            response.Result          = myUser;
                            response.IsSuccess       = true;
                        }
                        else
                        {
                            response.Message.Add(new MessageResult {
                                Message = "Usuario y/o contraseña no válido"
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        response = ResponseHelper <User> .ExceptionDatabase(ex, "Select", User.GetType().FullName, null);
                    }
                    return(Ok(response));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                response.Message.Add(new MessageResult {
                    Message = ex.Message
                });
                return(Ok(response));
            }
        }