コード例 #1
0
        public UpdateTeamMemberViewModel GetTeamMemberForUpdateById(short TeamMemberRowID)
        {
            try
            {
                UpdateTeamMemberViewModel model = new UpdateTeamMemberViewModel();
                var entity = db.TeamMembers.Find(TeamMemberRowID);

                if (entity != null)
                {
                    model.TeamMemberRowID  = entity.TeamMemberRowID;
                    model.TMTitle          = entity.TMTitle;
                    model.TMFirstName      = entity.TMFirstName;
                    model.TMLastName       = entity.TMLastName;
                    model.FTitle           = entity.FTitle;
                    model.FFirstName       = entity.FFirstName;
                    model.FLastName        = entity.FLastName;
                    model.SpouseFirstName  = entity.SpouseFirstName;
                    model.SpouseLastName   = entity.SpouseLastName;
                    model.DOB              = entity.DOB;
                    model.DOJ              = entity.DOJ;
                    model.CountryRowID     = entity.CountryRowID;
                    model.StateRowID       = entity.StateRowID;
                    model.DistrictRowID    = entity.DistrictRowID;
                    model.LocationRowID    = entity.LocationRowID;
                    model.PinCode          = entity.PinCode;
                    model.EmployeeID       = entity.EmployeeID;
                    model.CategoryRowID    = entity.CategoryRowID;
                    model.PresentAddress   = entity.PresentAddress;
                    model.PermanentAddress = entity.PermanentAddress;
                    model.STD              = entity.STD;
                    model.ResidancePhoneNo = entity.ResidancePhoneNo;
                    model.MobileNo         = entity.MobileNo;
                    model.EmailID          = entity.EmailID;
                    model.DirectTelNo      = entity.DirectTelNo;
                    model.ProcessStatus    = entity.ProcessStatus;
                    model.UserType         = entity.UserType;
                    model.Status           = entity.Status;
                    model.BORowID          = entity.BORowID;
                }
                else
                {
                    throw new Exception("Invalid Id!");
                }

                return(model);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
 public void UpdateTeamMember(UpdateTeamMemberViewModel model)
 {
     try
     {
         if (model != null && model.TeamMemberRowID > 0)
         {
             TeamMember entity = new TeamMember();
             entity.TeamMemberRowID  = model.TeamMemberRowID;
             entity.TMTitle          = model.TMTitle;
             entity.TMFirstName      = model.TMFirstName;
             entity.TMLastName       = model.TMLastName;
             entity.FTitle           = model.FTitle;
             entity.FFirstName       = model.FFirstName;
             entity.FLastName        = model.FLastName;
             entity.SpouseFirstName  = model.SpouseFirstName;
             entity.SpouseLastName   = model.SpouseLastName;
             entity.DOB              = model.DOB;
             entity.DOJ              = model.DOJ;
             entity.CountryRowID     = model.CountryRowID;
             entity.StateRowID       = model.StateRowID;
             entity.DistrictRowID    = model.DistrictRowID;
             entity.LocationRowID    = model.LocationRowID;
             entity.PinCode          = model.PinCode;
             entity.EmployeeID       = model.EmployeeID;
             entity.CategoryRowID    = model.CategoryRowID;
             entity.PresentAddress   = model.PresentAddress;
             entity.PermanentAddress = model.PermanentAddress;
             entity.STD              = model.STD;
             entity.ResidancePhoneNo = model.ResidancePhoneNo;
             entity.MobileNo         = model.MobileNo;
             entity.EmailID          = model.EmailID;
             entity.DirectTelNo      = model.DirectTelNo;
             entity.ProcessStatus    = model.ProcessStatus;
             entity.UserType         = model.UserType;
             entity.Status           = model.Status;
             entity.BORowID          = model.BORowID;
             db.Entry(entity).State  = EntityState.Modified;
         }
         else
         {
             throw new Exception("TeamMember could not be blank!");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #3
0
        public ActionResult EditTeamMember(short id = 0)
        {
            UpdateTeamMemberViewModel model = new UpdateTeamMemberViewModel();

            try
            {
                BindCountry();
                BindTitleList();
                BindTitleFatherList();
                BindCategoryList();
                BindDepartmentList();
                BindBranchOfficeList();
                //BindDesignationList();
                model = repoTeamMember.GetTeamMemberForUpdateById(id);
            }
            catch (Exception Ex)
            {
                ViewBag.ErrorMsg = Ex.Message;
                clsCommonMethods.ErrorLog(Server.MapPath("~\\ErrorLogs\\Logfiles"), Ex.Message, Ex.StackTrace);
            }

            return(View(model));
        }
コード例 #4
0
        public async Task <IActionResult> UpdateOrganizationMember(UpdateTeamMemberViewModel request, string personId, string organizationId)
        {
            var currentUser = await _userManager.FindByEmailAsync(_accessor.HttpContext.User.Identity.Name);

            OrganizationMember currentOrgMember = _organzationMemberRepo.Find(null, o => o.PersonId == Guid.Parse(personId)).Items?.FirstOrDefault();

            if (!currentOrgMember.IsAdministrator ?? false || currentOrgMember.OrganizationId != Guid.Parse(organizationId))
            {
                throw new UnauthorizedOperationException("Only admins of this organization can update existing users", EntityOperationType.Update);
            }

            var             userToUpdate   = _aspNetUsersRepository.Find(null, u => u.PersonId == Guid.Parse(personId)).Items?.FirstOrDefault();
            var             personToUpdate = _personRepo.Find(null, p => p.Id == Guid.Parse(personId)).Items?.FirstOrDefault();
            ApplicationUser appUser        = await _userManager.FindByIdAsync(userToUpdate.Id).ConfigureAwait(false);

            //check password's validity if one was provided
            if (!string.IsNullOrEmpty(request.Password))
            {
                if (!IsPasswordValid(request.Password))
                {
                    throw new Exception(PasswordRequirementMessage(request.Password));
                }
            }

            //if email was provided check its availability
            if (!string.IsNullOrEmpty(request.Email))
            {
                //if email is not the same as user's current email
                if (!appUser.NormalizedEmail.Equals(request.Email.ToUpper()))
                {
                    var existingEmailUser = _aspNetUsersRepository.Find(null, u => u.Email == request.Email).Items?.FirstOrDefault();

                    if (existingEmailUser != null)
                    {
                        throw new Exception("A user already exists for the provided email address");
                    }

                    var personEmailToUpdate       = _personEmailRepository.Find(null, p => p.PersonId == Guid.Parse(personId)).Items?.FirstOrDefault();
                    var emailVerificationToUpdate = _emailVerificationRepository.Find(null, p => p.PersonId == Guid.Parse(personId)).Items?.FirstOrDefault();

                    //update application user's email
                    appUser.Email              = request.Email;
                    appUser.NormalizedEmail    = request.Email.ToUpper();
                    appUser.UserName           = request.Email;
                    appUser.NormalizedUserName = request.Email.ToUpper();

                    //update additional email tables
                    personEmailToUpdate.Address       = request.Email;
                    emailVerificationToUpdate.Address = request.Email;

                    _personEmailRepository.Update(personEmailToUpdate);
                    _emailVerificationRepository.Update(emailVerificationToUpdate);
                }
            }

            //update name if one was provided
            if (!string.IsNullOrEmpty(request.Name))
            {
                appUser.Name        = request.Name;
                personToUpdate.Name = request.Name;

                _personRepo.Update(personToUpdate);
            }

            //update password
            if (!string.IsNullOrEmpty(request.Password))
            {
                appUser.ForcedPasswordChange = false;
                var token = await _userManager.GeneratePasswordResetTokenAsync(appUser);

                IdentityResult result = await _userManager.ResetPasswordAsync(appUser, token, request.Password);

                if (!result.Succeeded)
                {
                    throw new Exception("Failed to set new password");
                }
            }

            //update application user
            if (!string.IsNullOrEmpty(request.Password) || !string.IsNullOrEmpty(request.Email))
            {
                _userManager.UpdateAsync(appUser);
            }

            return(new OkObjectResult(appUser));
        }
コード例 #5
0
 public async Task <IActionResult> UpdateUser(string personId, string organizationId, [FromBody] UpdateTeamMemberViewModel request)
 {
     try
     {
         return(await _membershipManager.UpdateOrganizationMember(request, personId, organizationId));
     }
     catch (Exception ex)
     {
         return(ex.GetActionResult());
     }
 }
コード例 #6
0
 public async Task <IActionResult> UpdateUser(string personId, string organizationId, [FromBody] UpdateTeamMemberViewModel request)
 {
     try
     {
         return(await membershipManager.UpdateOrganizationMember(request, personId, organizationId));
     }
     catch (UnauthorizedAccessException unauthorized)
     {
         return(Unauthorized("Only Admins of this organization can update existing users"));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
コード例 #7
0
        public ActionResult EditTeamMember(UpdateTeamMemberViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool flag = false;
                    if (model.EmployeeID != null && model.EmployeeID.Trim().Length > 0)
                    {
                        if (!string.IsNullOrWhiteSpace(model.MobileNo))
                        {
                            if (model.MobileNo.Length < 10 || model.MobileNo.Length > 11)
                            {
                                flag = true;
                                ModelState.AddModelError("", "Enter Valid Mobile No");
                                //ViewBag.ErrorMsg = "Enter Valid Mobile No";
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(model.STD) && !string.IsNullOrWhiteSpace(model.ResidancePhoneNo))
                        {
                            if (model.STD.Length < 3)
                            {
                                flag = true;
                                ModelState.AddModelError("", "Enter valid STD Code");
                            }
                            else if (model.ResidancePhoneNo.Length < 6)
                            {
                                flag = true;
                                ModelState.AddModelError("", "Enter Valid Telephone No");
                            }
                        }
                        if (!flag)
                        {
                            if (!repoTeamMember.IsTeamMemberExist(model.TeamMemberRowID, model.EmployeeID.Trim()))
                            {
                                DateTime DateOfBirth = DateTime.Parse(model.DOB.ToString());
                                DateTime DateOfJoin  = DateTime.Parse(model.DOJ.ToString());
                                var      age         = DateOfJoin.Year - DateOfBirth.Year;
                                if (age >= 18)
                                {
                                    repoTeamMember.UpdateTeamMember(model);
                                    int Res = repoTeamMember.SaveChanges();
                                    if (Res > 0)
                                    {
                                        TempData["SuccessMsg"] = "Record Added Successfully!";
                                        ModelState.Clear();
                                        return(RedirectToAction("ManageTeamMembers"));
                                    }
                                    else
                                    {
                                        ViewBag.ErrorMsg = "There is no change!";
                                    }
                                }
                                else
                                {
                                    ViewBag.ErrorMsg = "Date Of Birth should be less than 18 years From join Date!";
                                }
                            }
                            else
                            {
                                ViewBag.ErrorMsg = "Record Already Exist!";
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "TeamMember Name could not be blank!");
                    }
                }
                else
                {
                    var query = from state in ModelState.Values
                                from error in state.Errors
                                select error.ErrorMessage;

                    var    errorList = query.ToList();
                    string strError  = string.Empty;
                    foreach (string str in errorList)
                    {
                        strError += str + "\n";
                    }

                    ModelState.AddModelError("", strError);
                }
            }
            catch (Exception Ex)
            {
                ViewBag.ErrorMsg = Ex.Message;
                clsCommonMethods.ErrorLog(Server.MapPath("~\\ErrorLogs\\Logfiles"), Ex.Message, Ex.StackTrace);
            }
            BindCountry();
            BindTitleList();
            BindTitleFatherList();
            BindCategoryList();
            BindDepartmentList();
            BindBranchOfficeList();
            //BindDesignationList();
            return(View());
        }