public ActionResult OrgInfo(OrgAdminInfoModel OrgAdminInfoModel) { int UserId = SurveyHelper.GetDecryptUserId(Session["UserId"].ToString()); int UserHighestRole = int.Parse(Session["UserHighestRole"].ToString()); string url = ""; if (this.Request.UrlReferrer == null) { url = this.Request.Url.ToString(); } else { url = this.Request.UrlReferrer.ToString(); } //Edit Organization if (OrgAdminInfoModel.IsEditMode) { ModelState.Remove("AdminFirstName"); ModelState.Remove("AdminLastName"); ModelState.Remove("ConfirmAdminEmail"); ModelState.Remove("AdminEmail"); OrganizationRequest Request = new OrganizationRequest(); UserDTO AdminInfo = new UserDTO(); AdminInfo.FirstName = ""; AdminInfo.LastName = ""; AdminInfo.EmailAddress = ""; AdminInfo.Role = 0; AdminInfo.PhoneNumber = ""; Request.OrganizationAdminInfo = AdminInfo; Request.Organization.Organization = OrgAdminInfoModel.OrgName; Request.Organization.IsEnabled = OrgAdminInfoModel.IsOrgEnabled; Request.Organization.OrganizationKey = GetOrgKey(url); Request.UserId = UserId; Request.UserRole = UserHighestRole; Request.Action = "UpDate"; try { OrganizationResponse Result = _isurveyFacade.SetOrganization(Request); OrganizationResponse Organizations = _isurveyFacade.GetUserOrganizations(Request); List <OrganizationModel> Model = Mapper.ToOrganizationModelList(Organizations.OrganizationList); OrgListModel OrgListModel = new OrgListModel(); OrgListModel.OrganizationList = Model; OrgListModel.Message = "Organization " + OrgAdminInfoModel.OrgName + " has been updated."; if (Result.Message.ToUpper() != "EXISTS" && Result.Message.ToUpper() != "ERROR") { OrgListModel.Message = "Organization " + OrgAdminInfoModel.OrgName + " has been updated."; return(View("OrgList", OrgListModel)); } else if (Result.Message.ToUpper() == "ERROR") { OrgAdminInfoModel OrgInfo = new OrgAdminInfoModel(); Request.Organization.OrganizationKey = GetOrgKey(url);; Organizations = _isurveyFacade.GetOrganizationInfo(Request); OrgInfo = Mapper.ToOrgAdminInfoModel(Organizations); OrgInfo.IsEditMode = true; ModelState.AddModelError("IsOrgEnabled", "Organization for the super admin cannot be deactivated."); return(View("OrgInfo", OrgInfo)); } else { OrgAdminInfoModel OrgInfo = new OrgAdminInfoModel(); Request.Organization.OrganizationKey = GetOrgKey(url);; Organizations = _isurveyFacade.GetOrganizationInfo(Request); OrgInfo = Mapper.ToOrgAdminInfoModel(Organizations); OrgInfo.IsEditMode = true; ModelState.AddModelError("OrgName", "The organization name provided already exists."); return(View("OrgInfo", OrgInfo)); } } catch (Exception ex) { return(View(OrgAdminInfoModel)); } } else { // Add new Organization if (ModelState.IsValid) { OrganizationRequest Request = new OrganizationRequest(); Request.Organization.Organization = OrgAdminInfoModel.OrgName; Request.Organization.IsEnabled = OrgAdminInfoModel.IsOrgEnabled; UserDTO AdminInfo = new UserDTO(); AdminInfo.FirstName = OrgAdminInfoModel.AdminFirstName; AdminInfo.LastName = OrgAdminInfoModel.AdminLastName; AdminInfo.EmailAddress = OrgAdminInfoModel.AdminEmail; AdminInfo.Role = 2; AdminInfo.PhoneNumber = "123456789"; AdminInfo.UGuid = Guid.NewGuid(); Request.OrganizationAdminInfo = AdminInfo; Request.UserRole = UserHighestRole; Request.UserId = UserId; Request.Action = "Insert"; try { OrganizationResponse Result = _isurveyFacade.SetOrganization(Request); OrgListModel OrgListModel = new OrgListModel(); OrganizationResponse Organizations = _isurveyFacade.GetUserOrganizations(Request); List <OrganizationModel> Model = Mapper.ToOrganizationModelList(Organizations.OrganizationList); OrgListModel.OrganizationList = Model; if (Result.Message.ToUpper() != "EXISTS") { OrgListModel.Message = "Organization " + OrgAdminInfoModel.OrgName + " has been created."; } else { // OrgListModel.Message = "The organization name provided already exists."; OrgAdminInfoModel OrgInfo = new OrgAdminInfoModel(); //Request.Organization.OrganizationKey = GetOrgKey(url); ; //Organizations = _isurveyFacade.GetOrganizationInfo(Request); OrgInfo = Mapper.ToOrgAdminInfoModel(Organizations); OrgInfo.IsEditMode = false; ModelState.AddModelError("OrgName", "The organization name provided already exists."); return(View("OrgInfo", OrgInfo)); } return(View("OrgList", OrgListModel)); } catch (Exception ex) { return(View(OrgAdminInfoModel)); } } else { return(View(OrgAdminInfoModel)); } } }