예제 #1
0
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // get company with id
            var company = _companyRepository.GetCompany(id.Value);

            if (company == null)
            {
                return(HttpNotFound());
            }

            // get connections
            var connections = _connectionRepository.Query().Include(nameof(Connection.Company1))
                              .Include(nameof(Connection.Company2))
                              .Where(x => x.CompanyId1 == id || x.CompanyId2 == id).ToList();

            var usersCompany = GetUserCompany();

            // make model for view
            var model = new CompanyViewModel(company)
            {
                Skills = db.CompanySkills.Include(s => s.Skill).Where(s => s.CompanyId == id).ToList(),
                ApprovedConnections = connections.Where(x => x.Status == ConnectionStatus.Approved).Select(x => x.CompanyId1 == id ? x.Company2 : x.Company1).ToList(),
                PendingConnections  = connections.Where(x => x.Status == ConnectionStatus.Requested && x.CompanyId1 == id).Select(x => x.CompanyId1 == id ? x.Company2 : x.Company1).ToList(),
                Followers           = _followerRepository.Query().Count(x => x.CompanyId == id),
                CurrentCompany      = usersCompany != null?Convert.ToInt32(usersCompany) : -1
            };

            // menage viewbag fields
            ViewBag.Success          = Session["ClaimSuccess"]?.ToString();
            Session["ClaimSuccess"]  = string.Empty;
            ViewBag.GoogleMapsApiKey = ConfigurationManager.AppSettings["GOOGLEMAPS_API_KEY"];

            // get best available address
            ViewBag.AddressForGoogleApi = this.GetBestAddress(model.Address2, model.Address1);

            // if company have no user, add clime opportunity
            var companyUser = await GetCompanyUser(id);

            if (companyUser == null)
            {
                return(View("ClaimingDetails", new ClaimingViewModel {
                    Company = model
                }));
            }

            return(View(model));
        }
예제 #2
0
        public async Task <ActionResult> BasicData(int id)
        {
            var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var userId      = User.GetClaimValue(Constants.UserIdClaim);

            //if (await userManager.IsInRoleAsync(userId, Constants.AdminRole) ||
            //(int.TryParse(User.GetClaimValue(Constants.CompanyIdClaim), out int userCompanyId) && await userManager.IsInRoleAsync(userId, Constants.CompanyRole) && userCompanyId == id))
            //{
            var company     = _companyRepository.GetCompanyWithDetails(id);
            var connections = _connectionsRepository.Query().Include(nameof(Connection.Company2)).Where(x => x.CompanyId1 == id || x.CompanyId2 == id).ToList();

            int.TryParse(User.GetClaimValue(Constants.CompanyIdClaim), out var currentCompany);

            var model = new CompanyViewModel(company)
            {
                Skills = _companySkillRepository.GetSkills(company.Id),
                ApprovedConnections  = connections.Where(x => x.Status == ConnectionStatus.Approved).Select(x => x.CompanyId1 == id ? x.Company2 : x.Company1).ToList(),
                PendingConnections   = connections.Where(x => x.Status == ConnectionStatus.Requested && x.CompanyId1 == id).Select(x => x.CompanyId1 == id ? x.Company2 : x.Company1).ToList(),
                CurrentCompany       = currentCompany,
                Employees            = company.Employees,
                NotificationSettings = await _notificationSettingsRepository.GetByUserId(userId)
            };

            ViewBag.Skills = _skillRepository.GetAll()
                             .Where(x => company.CompanySkills.All(y => y.SkillId != x.Id));

            if (model.NotificationSettings == null)
            {
                model.NotificationSettings = await _notificationSettingsRepository.Add(new NotificationSettings
                {
                    UserId = userId,
                    NotificationIteration = NotificationIteration.WithoutNotification
                });
            }
            ViewBag.GoogleMapsApiKey = ConfigurationManager.AppSettings["GOOGLEMAPS_API_KEY"];

            return(View(model));
            //}
            //else
            //{
            //    return new HttpUnauthorizedResult();
            //}
        }
        public ActionResult CheckForConnection(int companyId)
        {
            var partialName = "_ConnectButtonPartial";
            var role        = User.GetClaimValue(x => x.Type.Contains("role"));

            if (role != Common.Constants.CompanyRole)
            {
                return(Content(string.Empty));
            }

            if (int.TryParse(User.GetClaimValue(Common.Constants.CompanyIdClaim), out var connectedCompanyId))
            {
                if (companyId == connectedCompanyId)
                {
                    return(Content(string.Empty));
                }

                var connection = _connectionRepository.Query().FirstOrDefault(x => (x.CompanyId1 == companyId && x.CompanyId2 == connectedCompanyId) ||
                                                                              (x.CompanyId1 == connectedCompanyId && x.CompanyId2 == companyId));
                if (connection != null)
                {
                    switch (connection.Status)
                    {
                    case ConnectionStatus.Approved:
                        partialName = "_ConnectedButtonPartial";
                        break;

                    case ConnectionStatus.Requested:
                        partialName = "_WaitingForApprovalButtonPartial";
                        break;

                    case ConnectionStatus.Rejected:
                        return(Content(string.Empty));

                    default:
                        partialName = "_ConnectButtonPartial";
                        break;
                    }
                }
            }

            return(PartialView($"Buttons/{partialName}", companyId));
        }