Skip to content

Commit

Permalink
[DivisionDirectory] Fix head employee display
Browse files Browse the repository at this point in the history
in case of multiple head employees
  • Loading branch information
roman-yagodin committed Aug 9, 2016
1 parent 9f297be commit 7a4bcf7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,30 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using R7.University.Models;
using R7.University.Queries;

namespace R7.University.DivisionDirectory.Queries
{
internal class HeadEmployeeQuery: QueryBase
internal class HeadEmployeesQuery: QueryBase
{
public HeadEmployeeQuery (IModelContext modelContext): base (modelContext)
public HeadEmployeesQuery (IModelContext modelContext): base (modelContext)
{
}

public EmployeeInfo FirstOrDefault (int divisionId, int? headPositionId)
public IEnumerable<EmployeeInfo> GetHeadEmployees (int divisionId, int? headPositionId)
{
if (headPositionId != null) {
return ModelContext.Query<EmployeeInfo> ()
.Include (e => e.Positions)
.Include (e => e.Positions.Select (op => op.Position))
.Where (e => e.Positions.Any (op => op.DivisionID == divisionId && op.PositionID == headPositionId))
.FirstOrDefault ();
.ToList ();
}

return null;
return Enumerable.Empty<EmployeeInfo> ();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
<Compile Include="Components\DivisionDirectorySettings.cs" />
<Compile Include="Queries\HeadPositionQuery.cs" />
<Compile Include="Queries\DivisionHierarchyQuery.cs" />
<Compile Include="Queries\HeadEmployeeQuery.cs" />
<Compile Include="Queries\DivisionQuery.cs" />
<Compile Include="Queries\HeadEmployeesQuery.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
Expand Down
14 changes: 9 additions & 5 deletions R7.University.DivisionDirectory/ViewDivisionDirectory.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,11 @@ protected void gridDivisions_RowDataBound (object sender, GridViewRowEventArgs e
linkDocument.Visible = false;

// get head employee
var headEmployee = new HeadEmployeeQuery (ModelContext).FirstOrDefault (division.DivisionID, division.HeadPositionID);

if (headEmployee != null && headEmployee.IsPublished (now)) {
var headEmployee = new HeadEmployeesQuery (ModelContext)
.GetHeadEmployees (division.DivisionID, division.HeadPositionID)
.FirstOrDefault (he => he.IsPublished (now));

if (headEmployee != null) {
linkContactPerson.Text = headEmployee.AbbrName;
linkContactPerson.ToolTip = headEmployee.FullName;
linkContactPerson.NavigateUrl = EditUrl (
Expand Down Expand Up @@ -385,9 +387,11 @@ protected void gridObrnadzorDivisions_RowDataBound (object sender, GridViewRowEv
var literalContactPerson = (Literal) e.Row.FindControl ("literalContactPerson");

// get head employee
var headEmployee = new HeadEmployeeQuery (ModelContext).FirstOrDefault (division.DivisionID, division.HeadPositionID);
var headEmployee = new HeadEmployeesQuery (ModelContext)
.GetHeadEmployees (division.DivisionID, division.HeadPositionID)
.FirstOrDefault (he => he.IsPublished (now));

if (headEmployee != null && headEmployee.IsPublished (now)) {
if (headEmployee != null) {
var headPosition = headEmployee.Positions
.Single (op => op.DivisionID == division.DivisionID && op.PositionID == division.HeadPositionID);

Expand Down

0 comments on commit 7a4bcf7

Please sign in to comment.