public static int update(EAD_Project.PMS.Entities.UserDTO dto, string userGuid)//updates password where login
        {
            String sqlQuery = "";

            sqlQuery = String.Format("Update dbo.Users Set Password='******' WHERE Email='{1}')",
                                     dto.Password, dto.Email);
            using (DBHelper helper = new DBHelper())
            {
                return(helper.ExecuteQuery(sqlQuery));
            }
        }
        private static EAD_Project.PMS.Entities.UserDTO FillDTO1(SqlDataReader reader)
        {
            var dto = new EAD_Project.PMS.Entities.UserDTO();

            dto.UserID   = reader.GetInt32(0);
            dto.Name     = reader.GetString(1);
            dto.Login    = reader.GetString(2);
            dto.Password = reader.GetString(3);
            // dto.IsAdmin = Convert.ToBoolean(reader.GetByte(4));
            dto.IsAdmin     = reader.GetSqlBoolean(4).IsTrue;
            dto.IsActive    = reader.GetSqlBoolean(5).IsTrue;
            dto.PictureName = reader.GetString(6);
            dto.Designation = reader.GetString(7);
            dto.Email       = reader.GetString(8);
            return(dto);
        }
        public ActionResult updatePassword()
        {
            String email = Request.QueryString["email"];
            String code  = Request.QueryString["code"];

            // String code = Request.QueryString["code"].ToString();
            EAD_Project.PMS.Entities.UserDTO obj = BAL.UserBO.checkIsUser(email);
            if (obj.UserID > 0)
            {
                return(RedirectToAction("updatePassword1", "Home", obj));
            }
            else
            {
                return(Content("<script language='javascript' type='text/javascript'>alert('User don't exist!');</script>"));
            }
        }
        public ActionResult Login(EAD_Project.PMS.Entities.UserDTO u)
        {
            Shopping_DBEntities4 db = new Shopping_DBEntities4();
            var query = from d in db.Users
                        where (d.Password == u.Password && d.Name == u.Name)
                        select d;

            if (query != null)
            {
                var q = query.ToList();
                foreach (var x in q)
                {
                    u.IsAdmin = (bool)x.isAdmin;
                }
                Models.UserDTO result = new Models.UserDTO();
                result.IsAdmin = u.IsAdmin;
                EAD_Project.PMS.Entities.UserDTO obj = UserBO.ValidateUser(u.Name, u.Password);
                foreach (var x in q)
                {
                    if (query != null)
                    {
                        Session["User"] = obj;
                        if (result.IsAdmin)
                        {
                            //return Redirect("~/Home/Admin");
                            return(RedirectToAction("Admin"));
                        }
                        else
                        {
                            return(RedirectToAction("NormalUser"));
                        }
                    }
                }
                //else
                //{

                ViewBag.MSG   = "Invalid Login/Password";
                ViewBag.Login = u.Login;
                ModelState.AddModelError("", "UserName or Password does not match.");
                // return RedirectToAction("Login");
                return(Content("<script>alert('invalid user name or password');document.location='Login'</script>"));
                //}
            }
            return(Content("<script>alert('invalid user name or password');document.location='Login'</script>"));
        }
        public static EAD_Project.PMS.Entities.UserDTO checkIsUser(String email)//is uder with this login exists
        {
            var query = String.Format("Select * from dbo.Users Where Email={0}", email);

            using (DBHelper helper = new DBHelper())
            {
                var reader = helper.ExecuteReader(query);

                EAD_Project.PMS.Entities.UserDTO dto = null;
                if (reader.Read())
                {
                    dto = FillDTO1(reader);
                    return(dto);
                }

                return(dto);
            }
        }
        public static EAD_Project.PMS.Entities.UserDTO ValidateUser(String pLogin, String pPassword)
        {
            //  var query = String.Format("Select * from dbo.UsersTable Where Login='******' and Password='******'", pLogin, pPassword);
            var query = String.Format("Select * from dbo.Users Where Login='******' and Password='******'", pLogin, pPassword);

            using (DBHelper helper = new DBHelper())
            {
                var reader = helper.ExecuteReader(query);

                EAD_Project.PMS.Entities.UserDTO dto = null;

                if (reader.Read())
                {
                    dto = FillDTO1(reader);
                }

                return(dto);
            }
        }
 public static int update(EAD_Project.PMS.Entities.UserDTO dto, string userGuid)
 {
     return(DAL.User_DAO.update(dto, userGuid));
 }