Пример #1
0
        public ActionResult CheckLogin(string idUser, string password)
        {
            var result = new ResultData <User>()
            {
                Error = true, Status = HttpStatusCode.BadRequest
            };

            try
            {
                var user = db.Usuario.Where(q => q.IdUser == idUser).FirstOrDefault();
                if (UserServices.Access(user, idUser, password))
                {
                    result.Error = false;
                    result.Message.Add(user.Role.ToString());
                    result.Status = HttpStatusCode.OK;
                    return(Ok(result));
                }
                throw new ArgumentException("Acesso negado");
            }
            catch (Exception e)
            {
                result.Message.Add(e.Message);
                return(BadRequest(result));
            }
            finally
            {
                db.Dispose();
            }
        }