示例#1
0
        public JsonResult AddSkill(AddSkillViewModel vm)
        {
            var userSkill = new UserSkill
            {
                UserId  = WebUser.Id,
                SkillId = vm.SkillId,
            };

            _userSkillRepository.Create(userSkill);
            _unitOfWork.Commit();

            return(Json(true));
        }
示例#2
0
        public JsonResult AddSkill(AddSkillViewModel vm)
        {
            var selectedUser = _userRepository.Get(vm.UserId);

            if (selectedUser != null)
            {
                var userSkill = new UserSkill
                {
                    UserId  = selectedUser.Id,
                    SkillId = vm.SkillId
                };

                _userSkillRepository.Create(userSkill);
                _unitOfWork.Commit();

                return(Json(true));
            }

            return(Json(false));
        }
示例#3
0
        public ActionResult Update(NewUserViewModel vm)
        {
            ApiResult <User> apiResult;

            if (ModelState.IsValid)
            {
                if (vm.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var selectedUser                         = _userRepository.Get(vm.Id, "Person");
                        selectedUser.EmployeeCode                = vm.EmployeeCode;
                        selectedUser.Person.FirstName            = vm.Person.FirstName;
                        selectedUser.Person.MiddleName           = vm.Person.MiddleName;
                        selectedUser.Person.LastName             = vm.Person.LastName;
                        selectedUser.Person.Gender               = vm.Person.Gender;
                        selectedUser.Person.Email                = vm.Person.Email;
                        selectedUser.Person.PhoneNo              = vm.Person.PhoneNo;
                        selectedUser.Person.SecondaryEmail       = vm.Person.SecondaryEmail;
                        selectedUser.Person.Address              = vm.Person.Address;
                        selectedUser.Person.CommunicationAddress = vm.Person.CommunicationAddress;
                        selectedUser.Person.PassportNo           = vm.Person.PassportNo;
                        selectedUser.Person.DateOfBirth          = vm.Person.DateOfBirth;
                        selectedUser.Person.BloodGroup           = vm.Person.BloodGroup;
                        selectedUser.Person.MaritalStatus        = vm.Person.MaritalStatus;
                        selectedUser.Person.MarriageAnniversary  = vm.Person.MarriageAnniversary;
                        selectedUser.DepartmentId                = vm.DepartmentId;
                        selectedUser.LocationId                  = vm.LocationId;
                        selectedUser.DesignationId               = vm.DesignationId;
                        selectedUser.ShiftId                     = vm.ShiftId;
                        selectedUser.ReportingPersonId           = vm.ReportingPersonId;
                        selectedUser.Experience                  = vm.Experience;
                        selectedUser.DateOfJoin                  = vm.DateOfJoin;
                        selectedUser.ConfirmationDate            = vm.ConfirmationDate;
                        selectedUser.DateOfResignation           = vm.DateOfResignation;
                        selectedUser.LastDate                    = vm.LastDate;
                        selectedUser.OfficialEmail               = vm.OfficialEmail;
                        selectedUser.OfficialPhone               = vm.OfficialPhone;
                        selectedUser.OfficialMessengerId         = vm.OfficialMessengerId;
                        selectedUser.EmployeeStatus              = vm.EmployeeStatus;
                        selectedUser.RequiresTimeSheet           = vm.RequiresTimeSheet;
                        selectedUser.Salary                      = vm.Salary;
                        selectedUser.Bank                        = vm.Bank;
                        selectedUser.BankAccountNumber           = vm.BankAccountNumber;
                        selectedUser.PANCard                     = vm.PANCard;
                        selectedUser.PaymentMode                 = vm.PaymentMode;

                        _userRepository.Update(selectedUser);
                        _unitOfWork.Commit();

                        // Remove the existing mapped Roles
                        var existingRoles = _roleMemberRepository.GetAllBy(m => m.UserId == selectedUser.Id);
                        foreach (var map in existingRoles)
                        {
                            _roleMemberRepository.Delete(map);
                        }

                        if (vm.RoleIds != null)
                        {
                            // Map the New Technologies
                            foreach (var roleId in vm.RoleIds)
                            {
                                var newMap = new RoleMember
                                {
                                    UserId = vm.Id,
                                    RoleId = roleId
                                };

                                _roleMemberRepository.Create(newMap);
                            }

                            _unitOfWork.Commit();
                        }

                        // Remove the existing mapped Technologies
                        var existingMaps = _userTechnologyMapRepository.GetAllBy(m => m.UserId == selectedUser.Id);
                        foreach (var map in existingMaps)
                        {
                            _userTechnologyMapRepository.Delete(map);
                        }

                        _unitOfWork.Commit();

                        if (vm.TechnologyIds != null)
                        {
                            // Map the New Technologies
                            foreach (var technologyId in vm.TechnologyIds)
                            {
                                var newMap = new UserTechnologyMap
                                {
                                    UserId       = vm.Id,
                                    TechnologyId = technologyId
                                };

                                _userTechnologyMapRepository.Create(newMap);
                            }

                            _unitOfWork.Commit();
                        }


                        // Remove the existing mapped Skills
                        var existingSkillMaps = _userSkillRepository.GetAllBy(m => m.UserId == selectedUser.Id);
                        foreach (var map in existingSkillMaps)
                        {
                            _userSkillRepository.Delete(map);
                        }

                        _unitOfWork.Commit();

                        if (vm.SkillIds != null)
                        {
                            // Map the New Technologies
                            foreach (var skillId in vm.SkillIds)
                            {
                                var newMap = new UserSkill
                                {
                                    UserId  = vm.Id,
                                    SkillId = skillId
                                };

                                _userSkillRepository.Create(newMap);
                            }

                            _unitOfWork.Commit();
                        }

                        // Remove the existing mapped Skills
                        var existingHobbyMaps = _userHobbyRepository.GetAllBy(m => m.UserId == selectedUser.Id);
                        foreach (var map in existingHobbyMaps)
                        {
                            _userHobbyRepository.Delete(map);
                        }

                        _unitOfWork.Commit();

                        if (vm.HobbiesId != null)
                        {
                            // Map the New Technologies
                            foreach (var hobbyId in vm.HobbiesId)
                            {
                                var newMap = new UserHobby
                                {
                                    UserId  = vm.Id,
                                    HobbyId = hobbyId
                                };

                                _userHobbyRepository.Create(newMap);
                            }

                            _unitOfWork.Commit();
                        }

                        // Remove the existing mapped Certifications
                        var existingCertificationMaps =
                            _userCertificationRepository.GetAllBy(m => m.UserId == selectedUser.Id);
                        foreach (var map in existingCertificationMaps)
                        {
                            _userCertificationRepository.Delete(map);
                        }

                        _unitOfWork.Commit();

                        if (vm.CertificationIds != null)
                        {
                            // Map the New Technologies
                            foreach (var certificateId in vm.CertificationIds)
                            {
                                var newMap = new UserCertification
                                {
                                    UserId          = vm.Id,
                                    CertificationId = certificateId
                                };

                                _userCertificationRepository.Create(newMap);
                            }

                            _unitOfWork.Commit();
                        }

                        return(selectedUser);
                    }, "User updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var newUser = new User
                        {
                            EmployeeCode        = vm.EmployeeCode,
                            Username            = vm.Username,
                            Password            = HashHelper.Hash(vm.Password),
                            AccessRule          = AccessRule.CreateNewUserAccessRule(true),
                            Person              = vm.Person,
                            DepartmentId        = vm.DepartmentId,
                            LocationId          = vm.LocationId,
                            DesignationId       = vm.DesignationId,
                            ShiftId             = vm.ShiftId,
                            ReportingPersonId   = vm.ReportingPersonId,
                            Experience          = vm.Experience,
                            DateOfJoin          = vm.DateOfJoin,
                            ConfirmationDate    = vm.ConfirmationDate,
                            DateOfResignation   = vm.DateOfResignation,
                            LastDate            = vm.LastDate,
                            OfficialEmail       = vm.OfficialEmail,
                            OfficialPhone       = vm.OfficialPhone,
                            OfficialMessengerId = vm.OfficialMessengerId,
                            EmployeeStatus      = vm.EmployeeStatus,
                            RequiresTimeSheet   = vm.RequiresTimeSheet,
                            Salary              = vm.Salary,
                            Bank = vm.Bank,
                            BankAccountNumber = vm.BankAccountNumber,
                            PANCard           = vm.PANCard,
                            PaymentMode       = vm.PaymentMode
                        };

                        _userRepository.Create(newUser);
                        _unitOfWork.Commit();

                        // Map the Technologies
                        if (vm.TechnologyIds != null)
                        {
                            foreach (var technologyId in vm.TechnologyIds)
                            {
                                var newMap = new UserTechnologyMap
                                {
                                    UserId       = newUser.Id,
                                    TechnologyId = technologyId
                                };
                                _userTechnologyMapRepository.Create(newMap);
                            }

                            _unitOfWork.Commit();
                        }


                        // Map the Technologies
                        if (vm.RoleIds != null)
                        {
                            foreach (var roleId in vm.RoleIds)
                            {
                                var newMap = new RoleMember
                                {
                                    UserId = newUser.Id,
                                    RoleId = roleId
                                };

                                _roleMemberRepository.Create(newMap);
                            }

                            _unitOfWork.Commit();
                        }

                        return(newUser);
                    }, "User created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <User>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }