private IList <RelationshipDto> GetRelationShips() { IList <RelationshipDto> relationShipDtoList = new List <RelationshipDto>(); RelationShipServiceClient client = new RelationShipServiceClient(); relationShipDtoList = client.FindAll().Entities; client.Close(); return(relationShipDtoList); }
public ActionResult UserRegistration(UserRegistrationModel model) { UserServiceClient client = null; string userType = string.Empty; if (Request.QueryString["usertype"] != null) { userType = Request.QueryString["usertype"]; } try { ViewData["Error"] = null; TempData["Success"] = null; model.mode = CheckMode; foreach (StateDistrictCityControlNamesModel controlName in model.StateDistrictPlacesControlNames) { controlName.HiddenFieldForCityVillageValue = !String.IsNullOrEmpty(Request.Params[controlName.PlacesComboName + "_VI"]) ? Convert.ToInt32(Request.Params[controlName.PlacesComboName + "_VI"]) : 0; controlName.HiddenFieldForDistrictValue = !String.IsNullOrEmpty(Request.Params[controlName.DistrictComboName + "_VI"]) ? Convert.ToInt32(Request.Params[controlName.DistrictComboName + "_VI"]) : 0; controlName.HiddenFieldForStateValue = !String.IsNullOrEmpty(Request.Params[controlName.StateComboName + "_VI"]) ? Convert.ToInt32(Request.Params[controlName.StateComboName + "_VI"]) : 0; } if (EditorExtension.GetValue <object>("txtDateofBirth") != null) { model.DOB = EditorExtension.GetValue <DateTime>("txtDateofBirth"); } if (ComboBoxExtension.GetValue <object>("ddlECDesignation") != null) { model.UserDesignation = new DesignationDto { DesignationId = ComboBoxExtension.GetValue <int>("ddlECDesignation") }; } model.SelectedUserGroupList = !String.IsNullOrEmpty(Request.Params["SelectedUserGroupList"]) ? Request.Params["SelectedUserGroupList"] : ""; CheckForURValidation(model); client = new UserServiceClient(); UserDto CurrentUser = (UserDto)Session[Constants.SKCURRENTUSER]; UserDto NewUser = new UserDto(); if (ModelState.IsValid) { if (CheckMode == "Edit") { NewUser = client.GetById(model.UserId); } else { model.GeneratedPassword = Helper.Encode("password"); //Helper.Encode(Helper.GeneratePassword()); NewUser.Password = model.GeneratedPassword; } #region Registration if (model.UserOfClient.CAId != 0) { NewUser.UserOfClient = new ClientDto { CAId = model.UserOfClient.CAId }; } if (model.CAId != null && model.CAId > 0) { if (NewUser.UserOfClient == null) { NewUser.UserOfClient = new ClientDto(); } NewUser.UserOfClient.CAId = Convert.ToInt32(model.CAId); } NewUser.CAId = model.CAId; NewUser.UserName = model.UserName; NewUser.Title = model.Title; NewUser.Name = ConvertToCamelCase(model.Name); NewUser.DateOfBirth = model.DateOfBirth; NewUser.Email = model.Email; NewUser.CountryCode = model.CountryCode; NewUser.MobileNo = model.MobileNo; NewUser.IsActive = model.IsActive; NewUser.AllowDelete = true; NewUser.AllowEdit = true; NewUser.MothersMaidenName = model.MothersMaidenName; //NewUser.CreatedBy = CurrentUser.UserId; //NewUser.ModifiedBy = CurrentUser.UserId; #endregion #region UserGroupList string sUGList = Request.Params["SelectedUserGroupList"]; if (!String.IsNullOrEmpty(sUGList)) { UserGroupDto SelectedUG; string[] UGList = sUGList.Split(';'); NewUser.UserWithUserGroups = new List <UserGroupDto>(); foreach (string sUserGroupId in UGList) { int ugId = Convert.ToInt32(sUserGroupId); if (ugId != 0) { SelectedUG = new UserGroupDto { UserGroupId = ugId }; NewUser.UserWithUserGroups.Add(SelectedUG); } } } #endregion #region UserDesignation if (!Helper.IsCAIdNotNull(NewUser)) { NewUser.UserDesignation = new DesignationDto { DesignationId = model.UserDesignation.DesignationId }; } else { NewUser.UserDesignation = null; } #endregion #region DOB if (EditorExtension.GetValue <object>("txtDateofBirth") != null) { NewUser.DateOfBirth = EditorExtension.GetValue <DateTime>("txtDateofBirth"); } #endregion #region UploadedImage if (Session["UploadedImageFileName"] != null) { string imageNamewithGuid = Session["UploadedImageFileName"].ToString(); NewUser.Image = imageNamewithGuid; } #endregion #region UserProfile and Emergency Contact if (model.UserProfile != null) { #region UserProfile NewUser.UserProfile = model.UserProfile; //NewUser.UserProfile.ModifiedBy = CurrentUser.UserId; if (CheckMode == "Edit") { NewUser.UserProfile.UserProfileId = model.UserProfile.UserProfileId; } if (model.UserProfile.ContactNos != null) { List <ContactDetailsDto> contactDetailsDto = model.UserProfile.ContactNos.Where(x => x.ContactNo == null).ToList(); if (contactDetailsDto != null) { foreach (ContactDetailsDto contact in contactDetailsDto) { model.UserProfile.ContactNos.Remove(contact); } } } if (NewUser.UserProfile.ContactNos != null && NewUser.UserProfile.ContactNos.Count == 1) { if (NewUser.UserProfile.ContactNos[0].ContactNo == null) { NewUser.UserProfile.ContactNos.RemoveAt(0); } } int cityVillageID = 0; if (model.UserProfile.UserAddress != null) { NewUser.UserProfile.UserAddress = model.UserProfile.UserAddress; if (ComboBoxExtension.GetValue <object>("cmbCityVillage") != null) { cityVillageID = ComboBoxExtension.GetValue <int>("cmbCityVillage"); if (cityVillageID > 0) { NewUser.UserProfile.UserAddress.CityVillage = new CityVillageDto { CityVillageId = cityVillageID, }; } else { NewUser.UserProfile.UserAddress.CityVillage = null; } } if (CheckMode == "Edit" && model.UserProfile.UserAddress.CityVillage != null) { NewUser.UserProfile.UserAddress.CityVillage.CityVillageId = model.UserProfile.UserAddress.CityVillage.CityVillageId; } } #endregion #region UserEmergencyContactPerson if (!Helper.IsCAIdNotNull(NewUser) && model.UserProfile.UserEmergencyContactPerson != null) { NewUser.UserProfile.UserEmergencyContactPerson = model.UserProfile.UserEmergencyContactPerson; if (CheckMode == "Edit") { NewUser.UserProfile.UserEmergencyContactPerson.UserEmergencyContactPersonId = model.UserProfile.UserEmergencyContactPerson.UserEmergencyContactPersonId; } if (model.UserProfile.UserEmergencyContactPerson.Contacts != null) { List <ContactDetailsDto> contactDetailsDto = model.UserProfile.UserEmergencyContactPerson.Contacts.Where(x => x.ContactNo == null).ToList(); if (contactDetailsDto != null) { foreach (ContactDetailsDto contact in contactDetailsDto) { model.UserProfile.UserEmergencyContactPerson.Contacts.Remove(contact); } } } if (NewUser.UserProfile.UserEmergencyContactPerson.Contacts != null && NewUser.UserProfile.UserEmergencyContactPerson.Contacts.Count == 1) { if (string.IsNullOrEmpty(NewUser.UserProfile.UserEmergencyContactPerson.Contacts[0].ContactNo)) { NewUser.UserProfile.UserEmergencyContactPerson.Contacts.RemoveAt(0); } } if (model.UserProfile.UserEmergencyContactPerson.ContactPersonAddress != null) { NewUser.UserProfile.UserEmergencyContactPerson.ContactPersonAddress = model.UserProfile.UserEmergencyContactPerson.ContactPersonAddress; if (ComboBoxExtension.GetValue <object>("ECcmbCityVillage") != null) { cityVillageID = ComboBoxExtension.GetValue <int>("ECcmbCityVillage"); if (cityVillageID > 0) { NewUser.UserProfile.UserEmergencyContactPerson.ContactPersonAddress.CityVillage = new CityVillageDto { CityVillageId = cityVillageID, }; } else { NewUser.UserProfile.UserEmergencyContactPerson.ContactPersonAddress.CityVillage = null; } } if (CheckMode == "Edit" && model.UserProfile.UserEmergencyContactPerson.ContactPersonAddress.CityVillage != null) { NewUser.UserProfile.UserEmergencyContactPerson.ContactPersonAddress.CityVillage.CityVillageId = model.UserProfile.UserEmergencyContactPerson.ContactPersonAddress.CityVillage.CityVillageId; } } if (model.UserProfile.UserEmergencyContactPerson.ContactPersonRelationshipWithUser != null) { RelationShipServiceReference.IRelationShipService relationShipClient = new RelationShipServiceClient(); NewUser.UserProfile.UserEmergencyContactPerson.ContactPersonRelationshipWithUser = relationShipClient.GetById(model.UserProfile.UserEmergencyContactPerson.ContactPersonRelationshipWithUser.RelationshipId); } if (string.IsNullOrEmpty(NewUser.UserProfile.UserEmergencyContactPerson.Name)) { NewUser.UserProfile.UserEmergencyContactPerson = null; } //if (NewUser.UserProfile.UserEmergencyContactPerson != null) //{ // NewUser.UserProfile.UserEmergencyContactPerson.ModifiedBy = CurrentUser.UserId; //} } else { NewUser.UserProfile.UserEmergencyContactPerson = null; } #endregion } #endregion #region Service Request/Response NewUser.ViewOfUserUserGroupRolePermissions = null; NewUser.LastActivityDate = DateTime.Now; Session["UploadedImageFileName"] = null; if (CheckMode == "Edit") { if (NewUser.UserProfile != null) { NewUser.UserProfile.ModifiedBy = CurrentUser.UserId; } if (NewUser.UserProfile.UserAddress != null) { NewUser.UserProfile.UserAddress.ModifiedBy = CurrentUser.UserId; } if (NewUser.UserProfile.UserEmergencyContactPerson != null) { NewUser.UserProfile.UserEmergencyContactPerson.ModifiedBy = CurrentUser.UserId; } NewUser.ModifiedBy = CurrentUser.UserId; NewUser = client.Update(NewUser, CurrentUser.UserName); } else { if (NewUser.UserProfile != null) { NewUser.UserProfile.ModifiedBy = CurrentUser.UserId; NewUser.UserProfile.ModifiedBy = CurrentUser.UserId; } if (NewUser.UserProfile.UserAddress != null) { NewUser.UserProfile.UserAddress.ModifiedBy = CurrentUser.UserId; NewUser.UserProfile.UserAddress.ModifiedBy = CurrentUser.UserId; } if (NewUser.UserProfile.UserEmergencyContactPerson != null) { NewUser.UserProfile.UserEmergencyContactPerson.ModifiedBy = CurrentUser.UserId; NewUser.UserProfile.UserEmergencyContactPerson.ModifiedBy = CurrentUser.UserId; } NewUser.CreatedBy = CurrentUser.UserId; NewUser.ModifiedBy = CurrentUser.UserId; NewUser = client.Create(NewUser, CurrentUser.UserName); } if (NewUser.Response.HasWarning) { ViewData["Error"] = ErrorAndValidationMessages.URRegistrationFailed; int i = 0; foreach (BusinessWarning bw in NewUser.Response.BusinessWarnings) { if (bw.Message == "InValidUserAge") { if (Helper.IsCAIdNotNull(NewUser)) { ModelState.AddModelError("err" + (++i).ToString(), String.Format(ClientResources.InValidUserAge, Constants.CAUSERAGELIMIT)); } else { ModelState.AddModelError("err" + (++i).ToString(), String.Format(ClientResources.InValidUserAge, Constants.ACKUSERAGELIMIT)); } } else { ModelState.AddModelError("err" + (++i).ToString(), bw.Message); } } } else { if (CheckMode == "Edit") { TempData["UserRegisteredSuccessfully"] = "User updated successfully"; } else { TempData["UserRegisteredSuccessfully"] = ErrorAndValidationMessages.URRegistrationSuccessful; } if (model.CAId == null || model.CAId == 0) { return(RedirectToAction("UsersIndex", "Account", new { usertype = userType })); } else { return(RedirectToAction("UsersIndex", "Account", new { usertype = userType, CAId = model.CAId })); } } #endregion } else { ViewData["Error"] = ErrorAndValidationMessages.URRegistrationFailed; } if (!Helper.IsCAIdNotNull(NewUser)) { ViewData["DesignationList"] = GetUserDesignationList(); ViewData["SelectedDesignationId"] = model.UserDesignation.DesignationId; //ViewData["SelectedDesignationId"] = // (NewUser.UserDesignation != null) ? // (NewUser.UserDesignation.DesignationId > 0) ? // NewUser.UserDesignation.DesignationId : 0 : 0; } model.ECRelationshipWithUser = GetRelationShips(); Nullable <int> caID = null; if (!string.IsNullOrEmpty(Request.Params["CAId"])) { caID = Convert.ToInt32(Request.Params["CAId"]); } model.UserOfClient = GetClientById(); model.CAId = caID; model.UserGroupList = GetUserGroupList(caID); } catch (Exception ex) { return(RedirectToAction("Error")); } finally { if (client != null && client.State == System.ServiceModel.CommunicationState.Opened) { client.Close(); } } if (model.mode == "Edit") { if (Session["UploadedImageFileName"] != null) { model.Image = Session["UploadedImageFileName"].ToString(); } } return(View("UserRegistration", model)); }