public IHttpActionResult GetLogged(string userName, string passWord)
        {
            var users = db.Users.ToList();

            var cryptingFactory = new CryptingFactory();
            var cryptedpw       = users.Where(r => r.UserName == userName).First().Password;
            var uncryptedpw     = cryptingFactory.Decrypt(cryptedpw);
            var validpw         = passWord == uncryptedpw;

            //  string cryptedPassword = cryptingFactory.Encrypt(passWord);


            var validUser = users.Exists(r => r.UserName == userName && validpw);
            var user      = db.Users.Where(u => u.UserName == userName).FirstOrDefault();
            var userfav   = new UserFavoriteModel(user);

            if (validUser)
            {
                return(Ok(userfav));
            }
            else
            {
                return(BadRequest());
            }
        }
        public IHttpActionResult PostUser(User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var    cryptingFactory = new CryptingFactory();
            string cryptedPassword = cryptingFactory.Encrypt(user.Password);

            user.Password = cryptedPassword;

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

            return(CreatedAtRoute("DefaultApi", new { id = user.Id }, user));
        }
        public IHttpActionResult PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.Id)
            {
                return(BadRequest());
            }

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

            var    cryptingFactory = new CryptingFactory();
            string cryptedPassword = cryptingFactory.Encrypt(user.Password);

            user.Password = cryptedPassword;



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

            return(StatusCode(HttpStatusCode.NoContent));
        }