Beispiel #1
0
        /// <summary>
        /// Updates the organization.
        /// </summary>
        /// <returns><c>true</c>, if organization was updated, <c>false</c> otherwise.</returns>
        /// <param name="tenantId">Tenant identifier.</param>
        /// <param name="operatorId">Operator identifier.</param>
        /// <param name="org">Org.</param>
        public bool UpdateOrganization(int tenantId, int operatorId, OrganizationDO org)
        {
            var sql = "UPDATE public.organization SET name = @name, updatedby=@updatedby, updatedtime=@updatedtime WHERE tenantid=@tenantid and id = @Id";

            Execute(sql, org);
            return(true);
        }
        public Fr8AccountDO Register(IUnitOfWork uow, string userName, string firstName, string lastName,
                                     string password, string roleID, OrganizationDO organizationDO = null)
        {
            var userDO = uow.UserRepository.GetOrCreateUser(userName, roleID, organizationDO);

            uow.UserRepository.UpdateUserCredentials(userDO, userName, password);
            uow.AspNetUserRolesRepository.AssignRoleToUser(roleID, userDO.Id);

            //assign OwnerOfCurrentObject role to user
            uow.AspNetUserRolesRepository.AssignRoleToUser(Roles.OwnerOfCurrentObject, userDO.Id);

            return(userDO);
        }
Beispiel #3
0
        public OrganizationDTO UpdateOrganization(OrganizationDTO dto)
        {
            OrganizationDO curOrganization = null;

            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                curOrganization = uow.OrganizationRepository.GetByKey(dto.Id);
                if (curOrganization == null)
                {
                    throw new MissingObjectException($"There is no organization with Id {dto.Id}");
                }
                Mapper.Map(dto, curOrganization);
                uow.SaveChanges();
            }
            return(Mapper.Map <OrganizationDTO>(curOrganization));
        }
Beispiel #4
0
        /// <summary>
        /// Check if already exists some organization with the same name and create new if not
        /// </summary>
        /// <param name="organizationName"></param>
        /// <param name="isNewOrganization"></param>
        /// <returns></returns>
        public OrganizationDO GetOrCreateOrganization(IUnitOfWork uow, string organizationName, out bool isNewOrganization)
        {
            OrganizationDO organization = null;

            isNewOrganization = false;
            //check if organization already exist
            organization = uow.OrganizationRepository.GetQuery().FirstOrDefault(x => x.Name == organizationName);

            if (organization != null)
            {
                return(organization);
            }

            //create new organization
            organization = new OrganizationDO()
            {
                Name = organizationName
            };
            uow.OrganizationRepository.Add(organization);

            //create role for new organization and add System Administrator Profile to this role
            var memberOfOrganizationRole = new AspNetRolesDO()
            {
                Name = MemberOfOrganizationRoleName(organizationName),
            };

            uow.AspNetRolesRepository.Add(memberOfOrganizationRole);

            var adminRole = new AspNetRolesDO()
            {
                Name = AdminOfOrganizationRoleName(organizationName),
            };

            uow.AspNetRolesRepository.Add(adminRole);

            isNewOrganization = true;

            uow.SaveChanges();

            return(organization);
        }
        public static OrganizationDO ToDataObject(this Organization organization)
        {
            if (organization == null)
            {
                throw new ArgumentNullException(nameof(organization));
            }

            var entity = new OrganizationDO
            {
                Id          = organization.Id,
                TenantId    = organization.TenantId,
                ParentId    = organization.ParentId,
                Name        = organization.Name,
                Description = organization.Description,
                CreatedBy   = organization.CreatedBy,
                CreatedTime = organization.CreatedTime,
                UpdatedBy   = organization.UpdatedBy,
                UpdatedTime = organization.UpdatedTime
            };

            return(entity);
        }
Beispiel #6
0
        /// <summary>
        /// Creates the organization.
        /// </summary>
        /// <returns>The organization.</returns>
        /// <param name="tenantId">Tenant identifier.</param>
        /// <param name="operatorId">Operator identifier.</param>
        /// <param name="org">Org.</param>
        public long CreateOrganization(int tenantId, int operatorId, OrganizationDO org)
        {
            var sql = "INSERT INTO public.organization (tenantid, name, parentid, description, createdby, createdtime, updatedby, updatedtime) VALUES(@tenantid,@name,@parentid, @description, @createdby, @createdtime, @updatedby, @updatedtime) RETURNING id";

            return(ExecuteScalar <long>(sql, org));
        }
        public async Task <ActionResult> ProcessRegistration(RegistrationVM submittedRegData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    RegistrationStatus curRegStatus;
                    OrganizationDO     organizationDO = null;
                    bool isNewOrganization            = false;

                    using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
                    {
                        //check for organizations
                        if (submittedRegData.HasOrganization && !string.IsNullOrEmpty(submittedRegData.OrganizationName))
                        {
                            organizationDO = _organization.GetOrCreateOrganization(uow,
                                                                                   submittedRegData.OrganizationName, out isNewOrganization);
                        }

                        if (!String.IsNullOrWhiteSpace(submittedRegData.GuestUserTempEmail))
                        {
                            curRegStatus = await _account.UpdateGuestUserRegistration(uow, submittedRegData.Email.Trim()
                                                                                      , submittedRegData.Password.Trim()
                                                                                      , submittedRegData.GuestUserTempEmail, organizationDO);
                        }
                        else
                        {
                            curRegStatus = _account.ProcessRegistrationRequest(uow, submittedRegData.Email.Trim(),
                                                                               submittedRegData.Password.Trim(), organizationDO, isNewOrganization,
                                                                               submittedRegData.AnonimousId);
                        }

                        uow.SaveChanges();
                    }

                    if (curRegStatus == RegistrationStatus.UserMustLogIn)
                    {
                        ModelState.AddModelError("", @"You are already registered with us. Please login.");
                    }
                    else
                    {
                        return(this.Login(new LoginVM
                        {
                            Email = submittedRegData.Email.Trim(),
                            Password = submittedRegData.Password.Trim(),
                            RememberMe = false
                        }, string.Empty).Result);
                    }
                }
            }
            catch (ApplicationException appEx)
            {
                ModelState.AddModelError("", appEx.Message);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return(View("Register"));
        }
        /// <summary>
        /// Register Guest account
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="tempEmail"></param>
        /// <param name="organizationDO">Name of organization where the user belongs to</param>
        /// <returns></returns>
        public Task <RegistrationStatus> UpdateGuestUserRegistration(IUnitOfWork uow, string email, string password, string tempEmail, OrganizationDO organizationDO = null)
        {
            RegistrationStatus curRegStatus         = RegistrationStatus.Successful;
            Fr8AccountDO       newDockyardAccountDO = null;

            EmailAddressDO existingEmailAddressDO =
                uow.EmailAddressRepository.GetQuery().FirstOrDefault(ea => ea.Address == email);

            if (existingEmailAddressDO != null)
            {
                curRegStatus = RegistrationStatus.UserMustLogIn;
                return(Task.FromResult(curRegStatus));
            }

            //check if we know this email address

            EmailAddressDO guestUserexistingEmailAddressDO =
                uow.EmailAddressRepository.GetQuery().FirstOrDefault(ea => ea.Address == tempEmail);

            if (guestUserexistingEmailAddressDO != null)
            {
                var existingUserDO =
                    uow.UserRepository.GetQuery().FirstOrDefault(u => u.EmailAddressID == guestUserexistingEmailAddressDO.Id);

                // Update Email
                uow.UserRepository.UpdateUserCredentials(existingUserDO, email, password);

                // update organization
                if (organizationDO != null)
                {
                    existingUserDO.Organization = organizationDO;
                }

                guestUserexistingEmailAddressDO.Address = email;

                uow.AspNetUserRolesRepository.RevokeRoleFromUser(Roles.Guest, existingUserDO.Id);
                // Add new role
                uow.AspNetUserRolesRepository.AssignRoleToUser(Roles.StandardUser, existingUserDO.Id);
            }

            uow.SaveChanges();
            return(Task.FromResult(curRegStatus));
        }
        /// <summary>
        /// Register account
        /// </summary>
        /// <param name="uow"></param>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="organizationDO">organization where the user belongs</param>
        /// <param name="isNewOrganization">In case of new created organization, make user admin of that organization</param>
        /// <param name="anonimousId"></param>
        /// <returns></returns>
        public RegistrationStatus ProcessRegistrationRequest(IUnitOfWork uow, string email, string password, OrganizationDO organizationDO, bool isNewOrganization, string anonimousId)
        {
            RegistrationStatus curRegStatus;
            Fr8AccountDO       newFr8Account = null;
            //check if we know this email address

            EmailAddressDO existingEmailAddressDO =
                uow.EmailAddressRepository.GetQuery().FirstOrDefault(ea => ea.Address == email);

            if (existingEmailAddressDO != null)
            {
                var existingUserDO =
                    uow.UserRepository.GetQuery().FirstOrDefault(u => u.EmailAddressID == existingEmailAddressDO.Id);
                if (existingUserDO != null)
                {
                    if (existingUserDO.PasswordHash == null)
                    {
                        //this is an existing implicit user, who sent in a request in the past, had a DockyardAccountDO created, and now is registering. Add the password
                        UpdatePassword(uow, existingUserDO, password);
                        existingUserDO.Organization = organizationDO;

                        curRegStatus = RegistrationStatus.Successful;
                    }
                    else
                    {
                        //tell 'em to login
                        curRegStatus = RegistrationStatus.UserMustLogIn;
                    }
                }
                else
                {
                    newFr8Account = Register(uow, email, email, email, password, Roles.StandardUser, organizationDO);
                    curRegStatus  = RegistrationStatus.Successful;
                }
            }
            else
            {
                newFr8Account = Register(uow, email, email, email, password, Roles.StandardUser, organizationDO);
                curRegStatus  = RegistrationStatus.Successful;
            }

            if (newFr8Account != null)
            {
                if (organizationDO != null)
                {
                    AssingRolesAndProfilesBasedOnOrganization(uow, newFr8Account, organizationDO.Name, isNewOrganization);
                }
                else
                {
                    AssignProfileToUser(uow, newFr8Account, DefaultProfiles.StandardUser);
                }
            }

            uow.SaveChanges();

            if (newFr8Account != null)
            {
                EventManager.UserRegistration(newFr8Account);
                ObjectFactory.GetInstance <ITracker>().Registered(anonimousId, newFr8Account);
            }

            return(curRegStatus);
        }
        public OrganizationDO GetOrganizationBySubDomain(string subDomain)
        {
            int organizationId = _objOrganizationDAL.GetOrganizationBySubDomain(subDomain);

            OrganizationDO o = null;

            if (organizationId == 0)
            {
                return o;
            }

            DataTable dtOrganization = _objOrganizationDAL.GetOrganizationById(organizationId);

            if (dtOrganization.Rows.Count > 0)
            {
                o = new OrganizationDO();
                o.OrganizationId = Convert.ToInt32(dtOrganization.Rows[0]["OrganizationId"].ToString());
                o.LoginId = Convert.ToInt32(dtOrganization.Rows[0]["LoginId"].ToString());
                o.OrganizationName = dtOrganization.Rows[0]["OrganizationName"].ToString();
                o.CountryId = Convert.ToInt32(dtOrganization.Rows[0]["CountryId"].ToString());
                o.CountryName = dtOrganization.Rows[0]["CountryName"].ToString();
                if (dtOrganization.Rows[0]["StateId"].ToString() != "")
                    o.StateId = Convert.ToInt32(dtOrganization.Rows[0]["StateId"].ToString());
                else
                    o.StateId = 0;
                o.StateName = dtOrganization.Rows[0]["StateName"].ToString();
                if (dtOrganization.Rows[0]["CityId"].ToString() != "")
                    o.CityId = Convert.ToInt32(dtOrganization.Rows[0]["CityId"].ToString());
                else
                    o.CityId = 0;
                o.CityName = dtOrganization.Rows[0]["CityName"].ToString();
                o.BranchName = dtOrganization.Rows[0]["BranchName"].ToString();
                o.Address = dtOrganization.Rows[0]["Address"].ToString().Trim();
                o.AddressLine1 = dtOrganization.Rows[0]["AddressLine1"].ToString();
                o.AddressLine2 = dtOrganization.Rows[0]["AddressLine2"].ToString();
                o.PostalCode = dtOrganization.Rows[0]["PostalCode"].ToString();
                o.TimeZone = dtOrganization.Rows[0]["TimeZone"].ToString();
                o.Phone = dtOrganization.Rows[0]["Phone"].ToString();
                o.Mobile = dtOrganization.Rows[0]["Mobile"].ToString();
                o.InCharge = dtOrganization.Rows[0]["InCharge"].ToString();
                o.IsExternalReference = Convert.ToBoolean(dtOrganization.Rows[0]["IsExternalReference"].ToString());
                o.MaxAppointmentDays = Convert.ToInt32(dtOrganization.Rows[0]["MaxAppointmentDays"].ToString());
                o.IsApprovalSystem = Convert.ToBoolean(dtOrganization.Rows[0]["IsApprovalSystem"].ToString());
                o.IsCarParkFacility = Convert.ToBoolean(dtOrganization.Rows[0]["IsCarParkFacility"].ToString());
                o.IsConditionsPage = Convert.ToBoolean(dtOrganization.Rows[0]["IsConditionsPage"].ToString());
                o.SubDomain = dtOrganization.Rows[0]["SubDomain"].ToString();
                o.CNameUrl = dtOrganization.Rows[0]["CNameUrl"].ToString();
                o.WelcomeTitle = dtOrganization.Rows[0]["WelcomeTitle"].ToString();
                o.AboutOrganization = dtOrganization.Rows[0]["AboutOrganization"].ToString();
                o.ReferedBy = dtOrganization.Rows[0]["ReferedBy"].ToString();
                o.ReferenceToken = dtOrganization.Rows[0]["ReferenceToken"].ToString();
                o.CreatedOn = Convert.ToDateTime(dtOrganization.Rows[0]["CreatedOn"].ToString());
                o.IsDeleted = Convert.ToBoolean(dtOrganization.Rows[0]["IsDeleted"].ToString());
            }

            return o;
        }
    private void SaveOrganization()
    {
        //string titleCaseorganizationAddress = txtAddress.Text.ToLower();
        string titleCaseorganizationName = txtOrganizationName.Text.ToLower();
        //string titleCasepersonIncahrge = txtInCharge.Text.ToLower();
        //string titleCaseBranchName = txtBranchName.Text.ToLower();
        //string titleCaseRefferedBy = txtReferedBy.Text.ToLower();
        string titleCaseSubDomain = txtSubDomain.Text.ToLower();
        //txtAddress.Text = ToTitleCase(titleCaseorganizationAddress);
        txtOrganizationName.Text = ToTitleCase(titleCaseorganizationName);
        //txtInCharge.Text = ToTitleCase(titleCasepersonIncahrge);
        //txtBranchName.Text = ToTitleCase(titleCaseBranchName);
        //txtEmail.Text = txtEmail.Text.ToLower();
        //txtReferedBy.Text = ToTitleCase(titleCaseRefferedBy);
        txtSubDomain.Text = ToTitleCase(titleCaseSubDomain);

        OrganizationDO o = new OrganizationDO();
        //o.LoginId = Convert.ToInt32(Session["SignInLoginId"]);
        //o.OrganizationName = Regex.Replace(txtOrganizationName.Text.Trim(), @"\s+", " ");
        //o.CountryId = Convert.ToInt32(ddlCountry.SelectedValue);
        //if (trState.Visible)
        //    o.StateId = Convert.ToInt32(ddlState.SelectedValue);
        //else
        //    o.StateId = 0;
        //if (trCity.Visible)
        //    o.CityId = Convert.ToInt32(ddlCity.SelectedValue);
        //else
        //    o.CityId = 0;
        //o.BranchName = Regex.Replace(txtBranchName.Text.Trim(), @"\s+", " ");
        ////o.Address = null;
        //o.PostalCode = txtPostalCode.Text;
        //o.TimeZone = ddlTimeZone.SelectedValue;
        //o.Phone = null;
        //o.Mobile = hfMobile.Value;
        //o.InCharge = null;
        //o.IsExternalReference = Convert.ToBoolean(0);
        //o.MaxAppointmentDays = 0; //txtPriorDays.Text
        //o.IsApprovalSystem = false; //chkApprovalSystem.Checked
        //o.IsCarParkFacility = Convert.ToBoolean(0);
        //o.IsConditionsPage = Convert.ToBoolean(0);
        //o.SubDomain = txtSubDomain.Text; //sb.ToString();
        //o.CNameUrl = ""; //txtCNameUrl.Text;
        //o.WelcomeTitle = ""; //txtShortDescription.Text;
        //o.AboutOrganization = ""; //txtAboutOrganization.Text;
        //o.ReferedBy = null;
        //o.ReferenceToken = new CommonBAL().GetNewToken();

        int organizationId = new OrganizationBAL().SaveOrganization(txtOrganizationName.Text, txtSubDomain.Text);

        if (organizationId > 0)
        {
            Response.Redirect("Job_ManageAdmin.aspx");
            //ViewState["OrganizationId"] = organizationId;
            //organizationName = Regex.Replace(txtOrganizationName.Text.Trim(), @"\s+", " ") + " " + Regex.Replace(txtBranchName.Text.Trim(), @"\s+", " ");
            //ClientScriptManager cs = Page.ClientScript;
            //Type cType = this.GetType();
            //string cScript = "$(document).ready(function () { $.colorbox({ inline: true, width: \"700px\", href: \"#inline_content\" }) });";
            //cs.RegisterStartupScript(cType, "popup", cScript,true);
        }
    }
    private void SaveOrganization()
    {
        //string titleCaseorganizationAddress = txtAddress.Text.ToLower();
        string titleCaseorganizationName = txtOrganizationName.Text.ToLower();
        //string titleCasepersonIncahrge = txtInCharge.Text.ToLower();
        //string titleCaseBranchName = txtBranchName.Text.ToLower();
        //string titleCaseRefferedBy = txtReferedBy.Text.ToLower();
        string titleCaseSubDomain = txtSubDomain.Text.ToLower();

        //txtAddress.Text = ToTitleCase(titleCaseorganizationAddress);
        txtOrganizationName.Text = ToTitleCase(titleCaseorganizationName);
        //txtInCharge.Text = ToTitleCase(titleCasepersonIncahrge);
        //txtBranchName.Text = ToTitleCase(titleCaseBranchName);
        //txtEmail.Text = txtEmail.Text.ToLower();
        //txtReferedBy.Text = ToTitleCase(titleCaseRefferedBy);
        txtSubDomain.Text = ToTitleCase(titleCaseSubDomain);

        OrganizationDO o = new OrganizationDO();
        //o.LoginId = Convert.ToInt32(Session["SignInLoginId"]);
        //o.OrganizationName = Regex.Replace(txtOrganizationName.Text.Trim(), @"\s+", " ");
        //o.CountryId = Convert.ToInt32(ddlCountry.SelectedValue);
        //if (trState.Visible)
        //    o.StateId = Convert.ToInt32(ddlState.SelectedValue);
        //else
        //    o.StateId = 0;
        //if (trCity.Visible)
        //    o.CityId = Convert.ToInt32(ddlCity.SelectedValue);
        //else
        //    o.CityId = 0;
        //o.BranchName = Regex.Replace(txtBranchName.Text.Trim(), @"\s+", " ");
        ////o.Address = null;
        //o.PostalCode = txtPostalCode.Text;
        //o.TimeZone = ddlTimeZone.SelectedValue;
        //o.Phone = null;
        //o.Mobile = hfMobile.Value;
        //o.InCharge = null;
        //o.IsExternalReference = Convert.ToBoolean(0);
        //o.MaxAppointmentDays = 0; //txtPriorDays.Text
        //o.IsApprovalSystem = false; //chkApprovalSystem.Checked
        //o.IsCarParkFacility = Convert.ToBoolean(0);
        //o.IsConditionsPage = Convert.ToBoolean(0);
        //o.SubDomain = txtSubDomain.Text; //sb.ToString();
        //o.CNameUrl = ""; //txtCNameUrl.Text;
        //o.WelcomeTitle = ""; //txtShortDescription.Text;
        //o.AboutOrganization = ""; //txtAboutOrganization.Text;
        //o.ReferedBy = null;
        //o.ReferenceToken = new CommonBAL().GetNewToken();

        int organizationId = new OrganizationBAL().SaveOrganization(txtOrganizationName.Text, txtSubDomain.Text);

        if (organizationId > 0)
        {
            Response.Redirect("Job_ManageAdmin.aspx");
            //ViewState["OrganizationId"] = organizationId;
            //organizationName = Regex.Replace(txtOrganizationName.Text.Trim(), @"\s+", " ") + " " + Regex.Replace(txtBranchName.Text.Trim(), @"\s+", " ");
            //ClientScriptManager cs = Page.ClientScript;
            //Type cType = this.GetType();
            //string cScript = "$(document).ready(function () { $.colorbox({ inline: true, width: \"700px\", href: \"#inline_content\" }) });";
            //cs.RegisterStartupScript(cType, "popup", cScript,true);
        }
    }
        public Fr8AccountDO GetOrCreateUser(EmailAddressDO emailAddressDO, string userRole = Roles.StandardUser, OrganizationDO organizationDO = null)
        {
            var matchingUser = UnitOfWork.UserRepository.DBSet.Local.FirstOrDefault(u => u.EmailAddress.Address == emailAddressDO.Address);

            if (matchingUser == null)
            {
                matchingUser = UnitOfWork.UserRepository.GetQuery().FirstOrDefault(u => u.EmailAddress.Address == emailAddressDO.Address);
            }

            if (matchingUser == null)
            {
                matchingUser =
                    new Fr8AccountDO
                {
                    EmailAddress  = emailAddressDO,
                    UserName      = emailAddressDO.Address,
                    FirstName     = emailAddressDO.Name,
                    SecurityStamp = Guid.NewGuid().ToString(),
                    Organization  = organizationDO,
                    State         = UserState.Active
                };
                UnitOfWork.UserRepository.Add(matchingUser);

                if (!userRole.Equals(Roles.Guest))
                {
                    // Assign StandardUser role only if creation of Guest user is not intended
                    UnitOfWork.AspNetUserRolesRepository.AssignRoleToUser(Roles.StandardUser, matchingUser.Id);
                }
            }


            return(matchingUser);
        }
 public Fr8AccountDO GetOrCreateUser(String emailAddress, string userRole = Roles.StandardUser, OrganizationDO organizationDO = null)
 {
     return(GetOrCreateUser(UnitOfWork.EmailAddressRepository.GetOrCreateEmailAddress(emailAddress), userRole, organizationDO));
 }