Example #1
0
        public ActionResult DeactivateAnExistingUser(string id)
        {
            try
            {
                var allusers = from usertable in database.DX_USER where usertable.userid == id select usertable;
                if (allusers != null && allusers.ToList().Count == 1)
                {
                    DX_USER user = allusers.ToList().First();

                    switch (user.role)
                    {
                    case "ceo": user.accesslevel = Constants.DEACTIVATED_USER_ACCESS;
                        break;

                    case "manager": user.accesslevel = Constants.DEACTIVATED_USER_ACCESS;
                        break;

                    case "employee": user.accesslevel = Constants.DEACTIVATED_USER_ACCESS;
                        break;

                    case "vp": user.accesslevel = Constants.DEACTIVATED_USER_ACCESS;
                        break;

                    default:
                        break;
                    }
                    database.ObjectStateManager.ChangeObjectState(user, EntityState.Modified);
                    int success = database.SaveChanges();
                }
            }
            catch { ModelState.AddModelError("", "Error occured while tdeactivating the user"); }
            return(RedirectToAction("AllExistingUsers"));
        }
Example #2
0
        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));
        }