/// <summary>
 /// Deprecated Method for adding a new object to the DX_USER EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDX_USER(DX_USER dX_USER)
 {
     base.AddObject("DX_USER", dX_USER);
 }
        public ActionResult Register(RegisterModel model)
        {
            try
            {
                populateDepartmenetsList();

                if (ModelState.IsValid)
                {

                    FormsAuthentication.SignOut();
                    if (validateModelRegister(model) == false)
                    {
                        ViewBag.CaptchaGuid = Guid.NewGuid().ToString("N");
                        return View(model);
                    }

                    ViewBag.CaptchaGuid = Guid.NewGuid().ToString("N");

                    var allusers = from usertabel in database.DX_USER where usertabel.userid == model.Email select usertabel;
                    if (allusers.ToList().Count == 1)
                    {
                        ModelState.AddModelError("", "Email id not unique, please enter a diffrent valid email id!");
                        return View(model);

                    }
                    var alldepartment = from usertabel in database.DX_DEPARTMENT where model.Department.Contains(usertabel.deptid) select usertabel;

                    if (Constants.POSITION_CEO_USER.Equals(model.Position))
                    {

                        alldepartment = from usertabel in database.DX_DEPARTMENT select usertabel;

                    }

                    if (alldepartment.ToList().Count >= 1)
                    {

                        DX_USER user = new DX_USER();
                        user.fname = model.FirstName;
                        user.lname = model.LastName;
                        user.phone = model.Phone;
                        user.questionid = model.Squestion;
                        user.role = model.Position;
                        user.userid = model.Email;
                        user.anshash = generateHash(model.Answer.ToLower());
                        user.accesslevel = Constants.TEMP_USER_ACCESS;
                        user.salt = generateSalt();
                        user.pwdhash = generateHash(user.salt, model.Password);
                        user.actcodehash = "dummycode";
                        database.DX_USER.AddObject(user);//Add user

                        foreach (DX_DEPARTMENT dept in alldepartment.ToList())
                        {
                            DX_USERDEPT userDept = new DX_USERDEPT();
                            userDept.deptid = dept.deptid;
                            userDept.userid = model.Email;
                            database.DX_USERDEPT.AddObject(userDept);//Add department
                        }

                        int success = database.SaveChanges();
                        if (success > 0)
                        {
                            String message = Environment.NewLine + "Hi " + model.FirstName + "," + Environment.NewLine
                                + "Thank you for registering with Docbox!" + Environment.NewLine
                                + "You will soon get notification, once you are been approved by Docbox Administrator" + Environment.NewLine
                                    + "- Docbox Team";
                            try
                            {
                                EmailMessaging.sendMessage(model.Email, message, "Notification");
                            }
                            catch
                            {
                                ModelState.AddModelError("", "User created but unabe to log in at this point of time try logging in after some time!");

                                return View(model);
                            }

                            FormsAuthentication.SetAuthCookie(model.Email, false);
                            return RedirectToAction("Index", "TempUser");
                        }
                        else
                        {
                            ModelState.AddModelError("", "User can not be registered, Please try after some time!");
                            return View(model);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid Department Select Correct Department");
                        return View(model);
                    }

                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Invalid request please try after some time! ");
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }
 /// <summary>
 /// Create a new DX_USER object.
 /// </summary>
 /// <param name="userid">Initial value of the userid property.</param>
 /// <param name="fname">Initial value of the fname property.</param>
 /// <param name="lname">Initial value of the lname property.</param>
 /// <param name="role">Initial value of the role property.</param>
 /// <param name="pwdhash">Initial value of the pwdhash property.</param>
 /// <param name="questionid">Initial value of the questionid property.</param>
 /// <param name="phone">Initial value of the phone property.</param>
 /// <param name="anshash">Initial value of the anshash property.</param>
 /// <param name="accesslevel">Initial value of the accesslevel property.</param>
 /// <param name="salt">Initial value of the salt property.</param>
 public static DX_USER CreateDX_USER(global::System.String userid, global::System.String fname, global::System.String lname, global::System.String role, global::System.String pwdhash, global::System.Int32 questionid, global::System.String phone, global::System.String anshash, global::System.String accesslevel, global::System.String salt)
 {
     DX_USER dX_USER = new DX_USER();
     dX_USER.userid = userid;
     dX_USER.fname = fname;
     dX_USER.lname = lname;
     dX_USER.role = role;
     dX_USER.pwdhash = pwdhash;
     dX_USER.questionid = questionid;
     dX_USER.phone = phone;
     dX_USER.anshash = anshash;
     dX_USER.accesslevel = accesslevel;
     dX_USER.salt = salt;
     return dX_USER;
 }