public ActionResult UserView(UserViewModel userviewmodel)
        {
            using (var userinfo = new BLS_ClientEntities1())
            {
                var uinfo = (from u in userinfo.Users
                                    where u.UserId == userviewmodel.UserID
                                    select u).FirstOrDefault();
                if (uinfo != null)
                {
                    ModelState.AddModelError("UserId", "The User Id already exists.");
                    return View(userviewmodel);
                }
            }
            if (userviewmodel.User_Password != userviewmodel.Reenter_Password)
            {
                ModelState.AddModelError("User_Password", "Passwords do not match");
                return View(userviewmodel);
            }
            if (userviewmodel.Title == null)
            {
                ModelState.AddModelError("Title", "Title is required");
                return View(userviewmodel);
            }
            if (userviewmodel.Phone == null)
            {
                ModelState.AddModelError("Phone", "Phone is required");
                return View(userviewmodel);
            }
            if (userviewmodel.Email == null)
            {
                ModelState.AddModelError("Email", "Email is required");
                return View(userviewmodel);
            }

            User user = new User();
            user.Client = db.Clients.Find(userviewmodel.ParentId);
            user.Name = userviewmodel.ContactName;
            user.UserId = userviewmodel.UserID;
            user.Password = userviewmodel.User_Password;
            user.Password_ExpireDate = DateTime.Now.AddMonths(3);
            Contact contact = new Contact();

            contact.CellPhone = userviewmodel.CellPhone;
            contact.ContactName = userviewmodel.ContactName;
            contact.ContactType = userviewmodel.ContactType;
            contact.Email = userviewmodel.Email;
            if (userviewmodel.Fax == null)
                userviewmodel.Fax = "";
            contact.Fax = userviewmodel.Fax;
            contact.Gender = userviewmodel.Gender;
            contact.Phone = userviewmodel.Phone;
            contact.Title = userviewmodel.Title;
            user.Contacts.Add(contact);
            db.Users.Add(user);

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                ModelState.AddModelError("", "Error Updating Information");
                return View(userviewmodel);
            }
            ActiveUser AU = new ActiveUser();
            AU.ClientId = user.Client.Id;
            AU.UserId = userviewmodel.UserID;
            AU.Password = userviewmodel.User_Password;
            //Contact contact = uinfo.Contacts.FirstOrDefault();
            AU.UserName = contact.ContactName;

            Session["ActiveUser"] = AU;
            Session.Timeout = 120;
            bool ret = Create_DataBase(user.UserId, user.Password);
            return RedirectToAction("Download", "Clients");
        }
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                User uinfo = (from u in db.Users
                                where u.UserId == model.UserID && u.Password == model.Password
                                select u).FirstOrDefault();
                if (uinfo == null)
                {
                    ModelState.AddModelError("Password", "Invalid Login User ID/Password.");
                    return View(model);
                }

                ActiveUser AU = new ActiveUser();
                AU.ClientId = uinfo.Client.Id;
                AU.UserId = model.UserID;
                AU.Password = model.Password;
                Contact contact = uinfo.Contacts.FirstOrDefault();
                AU.UserName = contact.ContactName;

                Session["ActiveUser"] = AU;
                Session.Timeout = 120;
                Response.Redirect("~/Home/Index", false);
            }
            return View(model);
        }