protected void btnSignUp_Click(object sender, EventArgs e)
        {
            PropertySignUp propertySignUp = new PropertySignUp();
            Property       property       = new Property();
            PropertyUser   propertyUser   = new PropertyUser();

            property.Name               = txtPropertyName.Text;
            propertyUser.EmailAddress   = txtEmailAddress.Text;
            propertyUser.Password       = EncryptDecrypt.DESEncrypt(txtPassword.Text);
            propertyUser.UserType       = "Landlord";
            propertySignUp.property     = property;
            propertySignUp.propertyUser = propertyUser;
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(Configs.Global.BaseURL);
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var json = JsonConvert.SerializeObject(propertySignUp);
            var data = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = client.PostAsync(Configs.Global.SignUpURL, data).Result;

            if (response.IsSuccessStatusCode)
            {
                Response.Redirect("SignUpSucess.html");
            }
            else
            {
                StatusInfo objStatus = JsonConvert.DeserializeObject <StatusInfo>(response.Content.ReadAsStringAsync().Result);
                lblMessage.Text      = objStatus.Message;
                lblMessage.CssClass  = "label-error";
                txtEmailAddress.Text = "";
            }
        }
Beispiel #2
0
        public async Task UpdateProjectUser(ObjectId projectId, ObjectId userId, PropertyUserDTO projectUserDTO)
        {
            var user = await _userRepository.GetAsync(userId);

            if (user == null)
            {
                throw new HttpStatusException(400, $"The user {userId} does not exist");
            }

            if (userId != projectUserDTO.User.Id)
            {
                throw new HttpStatusException(400, "User id does not match");
            }

            var roleIds = from role in projectUserDTO.Roles
                          select role.Id;

            var newProjectUser = new PropertyUser()
            {
                UserId  = userId,
                RoleIds = roleIds.ToList(),
            };

            var existingProject = await _projectRepository.GetAsync(projectId);

            if (existingProject == null)
            {
                throw new HttpStatusException(404, "Invalid projectId");
            }

            Company company = await _companyRepository.GetAsync(existingProject.CompanyId);

            if (company is null)
            {
                throw new HttpStatusException(StatusCodes.Status400BadRequest, "Company not found.");
            }

            await AuthorizeUpdateAsync(company);

            var projectLeaderRole = Role.ProjectLeaderRole;

            if (projectLeaderRole != null && roleIds.Contains(projectLeaderRole.Id))
            {
                // Nutzer soll die Projektleiterrolle bekommen, in jedem Projekt
                // darf es aber nur einen ProjektLeiter geben

                var existingProjectLeader = from projectUser in existingProject.Users
                                            where projectUser.RoleIds.Contains(projectLeaderRole.Id)
                                            select projectUser;

                if (existingProjectLeader.Any())
                {
                    throw new HttpStatusException(403, "Cannot make two users a project Leader");
                }
            }

            existingProject.Users.ReplaceOrInsert(x => x.UserId == userId, newProjectUser);

            await _projectRepository.UpdateAsync(existingProject);
        }
        private void BindData()
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(Configs.Global.BaseURL);
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = client.GetAsync(Configs.Global.GetStaffById + "/" + staffId).Result;

            if (response.IsSuccessStatusCode)
            {
                PropertyUser objUser = JsonConvert.DeserializeObject <PropertyUser>(response.Content.ReadAsStringAsync().Result);
                if (!string.IsNullOrEmpty(objUser.EmailAddress))
                {
                    txtFirstName.Text               = objUser.FirstName;
                    txtLastName.Text                = objUser.LastName;
                    txtEmailAddress.Text            = objUser.EmailAddress;
                    txtPhoneNumber.Text             = objUser.PhoneNumber;
                    txtPassword.Attributes["value"] = EncryptDecrypt.DESDecrypt(objUser.Password);
                    if (objUser.UserType == "Landlord")
                    {
                        ddlUserType.Items.FindByValue("Landlord").Enabled = true;
                        ddlUserType.Enabled = false;
                    }
                    ddlUserType.SelectedValue = objUser.UserType;
                }
                else
                {
                    Response.Redirect("Staffs.aspx");
                }
            }
        }
Beispiel #4
0
 public PropertyUser GetUserInformation(int Id)
 {
     try
     {
         using (SqlConnection connection = new SqlConnection())
         {
             connection.ConnectionString = ConfigurationManager.ConnectionStrings["BizBuildingDB"].ToString();
             connection.Open();
             SqlCommand cmd = new SqlCommand("uspGetUserInformation", connection);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new SqlParameter("@UserId", Id));
             IDataReader  dr   = cmd.ExecuteReader();
             PropertyUser user = new PropertyUser();
             while (dr.Read())
             {
                 user.FirstName    = dr["first_name"] == System.DBNull.Value ? "" : Convert.ToString(dr["first_name"]);
                 user.LastName     = dr["last_name"] == System.DBNull.Value ? "" : Convert.ToString(dr["last_name"]);
                 user.EmailAddress = dr["email_address"] == System.DBNull.Value ? "" : Convert.ToString(dr["email_address"]);
                 user.Password     = dr["password"] == System.DBNull.Value ? "" : Convert.ToString(dr["password"]);
                 user.PhoneNumber  = dr["phone_number"] == System.DBNull.Value ? "" : Convert.ToString(dr["phone_number"]);
                 user.UserType     = dr["user_type"] == System.DBNull.Value ? "" : Convert.ToString(dr["user_type"]);
             }
             dr.Close();
             cmd.Dispose();
             connection.Close();
             return(user);
         }
     }
     catch (Exception ex) { }
     return(null);
 }
Beispiel #5
0
        public int SaveStaffInformation(PropertyUser user)
        {
            int userId = 0;

            try
            {
                using (SqlConnection connection = new SqlConnection())
                {
                    connection.ConnectionString = ConfigurationManager.ConnectionStrings["BizBuildingDB"].ToString();
                    connection.Open();
                    SqlCommand cmd = new SqlCommand("uspSaveStaffInformation", connection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@PropertyId", Convert.ToInt32(user.PropertyId)));
                    cmd.Parameters.Add(new SqlParameter("@UserId", Convert.ToInt32(user.UserId)));
                    cmd.Parameters.Add(new SqlParameter("@FName", user.FirstName));
                    cmd.Parameters.Add(new SqlParameter("@LName", user.LastName));
                    cmd.Parameters.Add(new SqlParameter("@EmailAddress", user.EmailAddress));
                    cmd.Parameters.Add(new SqlParameter("@PhoneNumber", user.PhoneNumber));
                    cmd.Parameters.Add(new SqlParameter("@UserType", user.UserType));
                    cmd.Parameters.Add(new SqlParameter("@Password", user.Password));
                    userId = (int)cmd.ExecuteScalar();
                    cmd.Dispose();
                    connection.Close();
                }
            }
            catch (Exception ex) { }
            return(userId);
        }
Beispiel #6
0
        public List <PropertyUser> GetStaffList(int Id)
        {
            List <PropertyUser> objStaffList = new List <PropertyUser>();

            try
            {
                using (SqlConnection connection = new SqlConnection())
                {
                    connection.ConnectionString = ConfigurationManager.ConnectionStrings["BizBuildingDB"].ToString();
                    connection.Open();
                    SqlCommand cmd = new SqlCommand("uspGetStaffList", connection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@PropertyId", Id));
                    IDataReader  dr = cmd.ExecuteReader();
                    PropertyUser user;
                    while (dr.Read())
                    {
                        user              = new PropertyUser();
                        user.UserId       = dr["user_id"] == System.DBNull.Value ? 0 : Convert.ToInt32(dr["user_id"]);
                        user.FirstName    = dr["first_name"] == System.DBNull.Value ? "" : Convert.ToString(dr["first_name"]);
                        user.LastName     = dr["last_name"] == System.DBNull.Value ? "" : Convert.ToString(dr["last_name"]);
                        user.EmailAddress = dr["email_address"] == System.DBNull.Value ? "" : Convert.ToString(dr["email_address"]);
                        user.PhoneNumber  = dr["phone_number"] == System.DBNull.Value ? "" : Convert.ToString(dr["phone_number"]);
                        user.UserType     = dr["user_type"] == System.DBNull.Value ? "" : Convert.ToString(dr["user_type"]);
                        objStaffList.Add(user);
                    }
                    dr.Close();
                    cmd.Dispose();
                    connection.Close();
                }
            }
            catch (Exception ex) { }
            return(objStaffList);
        }
Beispiel #7
0
        protected override async Task <Task> HandleRequirementAsync(AuthorizationHandlerContext context, OperationAuthorizationRequirement requirement, Issue issue)
        {
            ObjectId userId = context.User.GetUserId();

            if (context.User is null || issue is null)
            {
                return(Task.CompletedTask);
            }

            Project issueProject = await _projectRepository.GetAsync(issue.ProjectId);

            if (issueProject is null)
            {
                return(Task.CompletedTask);
            }

            Company issueCompany = await _companyRepository.GetAsync(issueProject.CompanyId);

            if (issueCompany is null)
            {
                return(Task.CompletedTask);
            }

            IEnumerable <State> projectStates = issueProject.States;

            if (projectStates is null)
            {
                return(Task.CompletedTask);
            }

            State currentIssueState = projectStates.FirstOrDefault(ps => ps.Id.Equals(issue.StateId));

            if (currentIssueState is null)
            {
                return(Task.CompletedTask);
            }

            PropertyUser projectUser = issueProject.Users?.FirstOrDefault(usr => usr.UserId.Equals(userId));
            PropertyUser companyUser = issueCompany.Users?.FirstOrDefault(usr => usr.UserId.Equals(userId));

            IList <ObjectId> userRoles = AuthorizationUtils.RolesOfUser(projectUser, companyUser);

            switch (currentIssueState.Phase)
            {
            case State.NegotiationPhase: ValidateRequirmentInNegotiationPhase(context, requirement, userRoles); break;

            case State.ProcessingPhase: ValidateRequirmentInProcessingPhase(context, requirement, userRoles); break;

            case State.ConclusionPhase: ValidateRequirmentInConclusionPhase(context, requirement, userRoles); break;
            }

            return(Task.CompletedTask);
        }
        public HttpResponseMessage GetUserInformation(int Id)
        {
            PropertyUser user = _repository.GetUserInformation(Id);

            if (user != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, user));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "N"));
            }
        }
Beispiel #9
0
 public LogInformation GetLogInformation(int LogId)
 {
     try
     {
         LogInformation logInformation = new LogInformation();
         using (SqlConnection connection = new SqlConnection())
         {
             connection.ConnectionString = ConfigurationManager.ConnectionStrings["BizBuildingDB"].ToString();
             connection.Open();
             SqlCommand cmd = new SqlCommand("uspGetLogInformation", connection);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new SqlParameter("@LogId", LogId));
             IDataReader         dr       = cmd.ExecuteReader();
             List <PropertyUser> objUsers = new List <PropertyUser>();
             PropertyUser        user;
             while (dr.Read())
             {
                 user           = new PropertyUser();
                 user.UserId    = dr["user_id"] == System.DBNull.Value ? 0 : Convert.ToInt32(dr["user_id"]);
                 user.FirstName = dr["first_name"] == System.DBNull.Value ? "" : Convert.ToString(dr["first_name"]);
                 user.LastName  = dr["last_name"] == System.DBNull.Value ? "" : Convert.ToString(dr["last_name"]);
                 objUsers.Add(user);
             }
             dr.NextResult();
             TenantLog objTenantLog = new TenantLog();
             while (dr.Read())
             {
                 objTenantLog.Location      = dr["location"] == System.DBNull.Value ? "" : Convert.ToString(dr["location"]);
                 objTenantLog.GeoLocation   = dr["geolocation"] == System.DBNull.Value ? "" : Convert.ToString(dr["geolocation"]);
                 objTenantLog.Description   = dr["description"] == System.DBNull.Value ? "" : Convert.ToString(dr["description"]);
                 objTenantLog.AssignedTo    = dr["assigned_to"] == System.DBNull.Value ? (int?)null : Convert.ToInt32(dr["assigned_to"]);
                 objTenantLog.AssignedName  = dr["assignedname"] == System.DBNull.Value ? "" : Convert.ToString(dr["assignedname"]).TrimEnd();
                 objTenantLog.Status        = dr["status"] == System.DBNull.Value ? "" : Convert.ToString(dr["status"]);
                 objTenantLog.CategoryName  = dr["categoryname"] == System.DBNull.Value ? "" : Convert.ToString(dr["categoryname"]);
                 objTenantLog.RequestedDate = dr["requested_date"] == System.DBNull.Value ? DateTime.Now : Convert.ToDateTime(dr["requested_date"]);
                 objTenantLog.ResolveDate   = dr["resolve_date"] == System.DBNull.Value ? (DateTime?)null : Convert.ToDateTime(dr["resolve_date"]);
             }
             dr.Close();
             cmd.Dispose();
             connection.Close();
             logInformation.Users           = objUsers;
             logInformation.TenantComplaint = objTenantLog;
             return(logInformation);
         }
     }
     catch (Exception ex) { }
     return(null);
 }
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RoleRequirement requirement, T resource)
        {
            ObjectId             userId         = context.User.GetUserId();
            ObjectId             requiredRoleId = requirement.Role.Id;
            IList <PropertyUser> propertyUsers  = resource.Users;

            PropertyUser reqestedUser = propertyUsers?.FirstOrDefault(pu => pu.UserId.Equals(userId));

            // if user complies the required role.
            if (reqestedUser is not null && reqestedUser.RoleIds.Any(ri => ri.Equals(requiredRoleId)))
            {
                context.Succeed(requirement);
            }

            return(Task.CompletedTask);
        }
        public async Task <bool> UserHasRoleInCompany(ObjectId userId, ObjectId companyId, params string[] requiredRoleNames)
        {
            // no roles to check
            if (requiredRoleNames.Any() is false)
            {
                return(true);
            }

            Company company = await _companyRepository.GetAsync(companyId);

            if (company is null)
            {
                throw new HttpStatusException(StatusCodes.Status400BadRequest, "Company not found.");
            }

            PropertyUser companyUser = company.Users.Where(user => user.UserId.Equals(userId)).FirstOrDefault();

            if (companyUser is null)
            {
                throw new HttpStatusException(StatusCodes.Status400BadRequest, "Error determin company roles for user.");
            }

            // TODO: Role class could serve a dict. with roles...
            var roles = await _roleRepository.GetAsync();

            foreach (var requiredRoleName in requiredRoleNames)
            {
                var requiredRole = roles.Where(r => r.Name.Equals(requiredRoleName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (requiredRole is null)
                {
                    throw new HttpStatusException(StatusCodes.Status400BadRequest, $"No role found with name: {requiredRoleName}");
                }

                if (companyUser.RoleIds.Contains(requiredRole.Id))
                {
                    return(true);
                }
            }

            return(false);
        }
        public HttpResponseMessage SaveStaff(PropertyUser user)
        {
            int userId = _repository.SaveStaffInformation(user);

            if (userId > 0)
            {
                StatusInfo objStatus = new StatusInfo();
                objStatus.Message = string.Format(Resources.Messages.SaveSuccess, "Staff");
                dynamic info = new
                {
                    UserId = userId
                };
                objStatus.Info = info;
                return(Request.CreateResponse(HttpStatusCode.OK, objStatus));
            }
            else if (userId == -1)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Format(Resources.Messages.EmailAddressExists, user.EmailAddress)));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Resources.Messages.InvalidData));
            }
        }
        protected void lnkSubmit_Click(object sender, EventArgs e)
        {
            UserInformation objUserInfo = (UserInformation)Session["UserInfo"];

            propertyId = objUserInfo.PropertyId;
            PropertyUser objUser = new PropertyUser();

            objUser.UserId       = staffId;
            objUser.FirstName    = txtFirstName.Text;
            objUser.LastName     = txtLastName.Text;
            objUser.EmailAddress = txtEmailAddress.Text;
            objUser.PhoneNumber  = txtPhoneNumber.Text;
            objUser.Password     = EncryptDecrypt.DESEncrypt(txtPassword.Text);
            objUser.UserType     = ddlUserType.SelectedValue;
            objUser.PropertyId   = propertyId;
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(Configs.Global.BaseURL);
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var json = JsonConvert.SerializeObject(objUser);
            var data = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = client.PostAsync(Configs.Global.SaveStaff, data).Result;

            if (response.IsSuccessStatusCode)
            {
                Session["SaveSuccess"] = "1";
                Response.Redirect("Staffs.aspx");
            }
            else
            {
                StatusInfo objStatus = JsonConvert.DeserializeObject <StatusInfo>(response.Content.ReadAsStringAsync().Result);
                lblError.Text     = objStatus.Message;
                lblError.CssClass = "label-error";
            }
        }
        public async Task EnsureSeedData()
        {
            if (await _userManager.FindByEmailAsync("*****@*****.**") == null)
            {
                var user = new User()
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                await _userManager.CreateAsync(user, "Door01@!");
            }

            if (await _userManager.FindByEmailAsync("*****@*****.**") == null)
            {
                var user = new User()
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                await _userManager.CreateAsync(user, "Door02@!");
            }

            if (await _userManager.FindByEmailAsync("*****@*****.**") == null)
            {
                var user = new User()
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };

                await _userManager.CreateAsync(user, "Door03@!");
            }

            var demoUser = await _userManager.FindByEmailAsync("*****@*****.**");

            if (!_context.PropertyUser.Any(x => x.UserId == demoUser.Id))
            {
                var property = new Property()
                {
                    Name  = "Office",
                    Doors = new List <Door>()
                };

                _context.Properties.Add(property);
                await _context.SaveChangesAsync();

                var firstDoor = new Door()
                {
                    Name       = "Tunnel Door",
                    Token      = Guid.NewGuid().ToString(),
                    IsOpen     = false,
                    PropertyId = property.Id
                };

                var secondDoor = new Door()
                {
                    Name       = "Office Door",
                    Token      = Guid.NewGuid().ToString(),
                    IsOpen     = false,
                    PropertyId = property.Id
                };

                _context.Doors.Add(firstDoor);
                _context.Doors.Add(secondDoor);

                var propertyUser = new PropertyUser()
                {
                    PropertyId = property.Id,
                    UserId     = demoUser.Id
                };

                _context.PropertyUser.Add(propertyUser);

                await _context.SaveChangesAsync();
            }
        }