Exemplo n.º 1
0
        public ActionResult Create(string EmployeeId, int[] RoleId)
        {
            // IEmployeeService eService = new EmployeeService();
               // var Uemployee = eService.GetEmpByUserId(Convert.ToInt32(EmployeeId));

            var userInRole = userInRoleService.GetRoleListByUser(Convert.ToInt64(EmployeeId));
               // var userInRole = rService.GetAllRoles();
            foreach (var item in userInRole)
            {
                var uIR = new UserInRole();
                if (RoleId.Contains(item.RoleId))
                {

                    uIR.EmployeeId = Convert.ToInt32(EmployeeId);
                    uIR.RoleId = Convert.ToInt32(item.RoleId);
                    uIR.IsActive = true;
                }
                else
                {
                    uIR.EmployeeId = Convert.ToInt32(EmployeeId);
                    uIR.RoleId = Convert.ToInt32(item.RoleId);
                    uIR.IsActive = false;
                }
                userInRoleService.AddUserInRole(uIR);

            }
            TempData.Add("SucMsg","Role Added Successfully");
            return RedirectToAction("Index", "UserInRoles", new { area = "UserManagement" });
        }
Exemplo n.º 2
0
        public bool AddUserInRole(UserInRole userInRole)
        {
            try
            {
                var ur = userInRoleRep.GetOperation()
                              .Filter(u => u.RoleId == userInRole.RoleId && u.EmployeeId == userInRole.EmployeeId)
                              .Get()
                              .FirstOrDefault();
                if (ur == null)
                {
                    userInRole.State = ObjectState.Added;
                    userInRoleRep.AddOperation(userInRole);
                    userInRole.State = ObjectState.Unchanged;
                    return true;
                }
                else {
                    userInRole.Id = ur.Id;
                    return UpdateUserInRole(userInRole);
                }

            }
            catch (Exception ex)
            {
                var rr = ex.Message;
                return false;
            }
        }
Exemplo n.º 3
0
        public ActionResult InvitationConfirm(int id, User user)
        {
            var tnc = Request.Params.Get("tnc");
            if (tnc != null && tnc == "on")
            {
                Encryptor encrypt = new Encryptor();
                user.Password = encrypt.GetMD5(user.Password);
                user.ConfirmPassword = encrypt.GetMD5(user.ConfirmPassword);
                if (uService.GetSingleUserByEmail(user.Email) == null)
                {

                    if (uService.AddUser(user))
                    {
                        var Invitation = inService.GetSingleInvitation(id);
                        var emp = new Employee();

                        var setObj = setService.GetAllByUserId(user.Id);
                        var logEntry = new CompanyViewLog();
                        logEntry.UserId = user.Id;
                        logEntry.CompanyId = Invitation.CompanyId; ;
                        logEntry.LoginTime = DateTime.Now;
                        //logEntry.IpAddress = "";
                        _companyViewLog.AddCompanyViewLog(logEntry);

                        emp.UserId = user.Id;
                        emp.CompanyId = Invitation.CompanyId;
                        emp.DesignationId = Invitation.DesignationId;
                        if (eService.CreateEmployee(emp))
                        {
                            var accountSetting = new Settings();
                            accountSetting.userId = user.Id;
                            accountSetting.lgdash = false;
                            accountSetting.lglast = false;
                            accountSetting.lgcompany = true;
                            accountSetting.CompanyId = Invitation.CompanyId;

                            if (sService.AddSettings(accountSetting))
                            {
                                var userInRole = new UserInRole();
                                userInRole.EmployeeId = emp.Id;
                                userInRole.RoleId = Invitation.RoleId;
                                userInRole.IsActive = true;
                                if (URSer.AddUserInRole(userInRole))
                                {
                                    CustomPrincipal.Login(user.Email, user.Password, false);
                                    return RedirectToAction("Create", "EmployeeProfile", new { area = "OrganizationManagement" });
                                }
                            }
                        }
                        else
                        {
                            return Content("Failed");
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("Msg", "Already Register");
                    //return Content("Already Register");
                    return View();

                }
            }

            return Content("You Must Agree with our terms and Condition");
        }
Exemplo n.º 4
0
        public bool UpdateUserInRole(UserInRole userInRole)
        {
            try
            {
                var dbObj = userInRoleRep.GetSingleObject(userInRole.Id);

                dbObj.IsActive = userInRole.IsActive;
                dbObj.State = ObjectState.Modified;
                userInRoleRep.UpdateOperation(dbObj);
                userInRole.State = ObjectState.Unchanged;
                return true;
            }
            catch (Exception ex)
            {
                var rr = ex.Message;
                return false;
            }
        }
Exemplo n.º 5
0
        public ActionResult InvitationConfirm(int id, string token)
        {
            var Invitation = inService.GetSingleInvitation(id);
            if (Invitation != null)
            {
                if (Invitation.Token == token)
                {
                    if (Invitation.Status != StatusEnum.test2)
                    {

                        Invitation.Status = StatusEnum.test2;
                        inService.AcceptInvitation(Invitation);
                        ViewBag.Company = Invitation.CompanyId;
                        ViewBag.email = Invitation.Email;
                        var user = uService.GetSingleUserByEmail(Invitation.Email);
                        if (user == null)
                        {
                            return View("InvitationConfirm");
                        }
                        else
                        {
                            var emp = new Employee();
                            emp.UserId = user.Id;
                            emp.CompanyId = Invitation.CompanyId;
                            emp.DesignationId = Invitation.DesignationId;
                            if (eService.CreateEmployee(emp))
                            {
                                var userInRole = new UserInRole();
                                userInRole.EmployeeId = emp.Id;
                                userInRole.RoleId = Invitation.RoleId;
                                userInRole.IsActive = true;
                                URSer.AddUserInRole(userInRole);

                                Session.Add("msg", "You have to login first");
                                return Redirect(Url.Content("~/"));

                            }
                            else
                            {
                                return Content("Employee Profile couldn't be completed");
                            }
                        }

                    }
                    else
                    {
                        return Content("You are trying to use a token that is already used !");
                    }

                    // return RedirectToAction("Index");
                }
                else
                {
                    return Content("token mismatch");
                }
            }
            else
            {
                return Content("Invitation Not Found!");
            }
        }