225 lines
6.0 KiB
C#
225 lines
6.0 KiB
C#
using EnVisage.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
|
|
namespace EnVisage.Code.BLL
|
|
{
|
|
//TODO: remove if obsolete
|
|
|
|
//public class MixManager : ManagerBase<Mix, MixSaveModel>, IMixManager<Mix>
|
|
//{
|
|
// public MixManager(EnVisageEntities dbContext)
|
|
// : base(dbContext)
|
|
// {
|
|
// }
|
|
|
|
// protected override Mix InitInstance()
|
|
// {
|
|
// return new Mix()
|
|
// {
|
|
// Id = Guid.NewGuid()
|
|
// };
|
|
// }
|
|
|
|
// protected override Mix RetrieveReadOnlyById(Guid key)
|
|
// {
|
|
// return DataTable.AsNoTracking().FirstOrDefault(x => x.Id == key);
|
|
// }
|
|
|
|
// public override Mix Save(MixSaveModel model)
|
|
// {
|
|
// var mix = new Mix();
|
|
// if (Guid.Empty.Equals(model.Id))
|
|
// {
|
|
// mix = base.Save(model);
|
|
// }
|
|
// else
|
|
// {
|
|
// mix = RetrieveWithRelations(model.Id);
|
|
// model.CopyTo(mix);
|
|
// DbContext.Entry(mix).State = EntityState.Modified;
|
|
// }
|
|
|
|
// SaveTeams(mix, model.Teams);
|
|
// SaveViews(mix, model.Views);
|
|
// SaveUsers(mix, model.Users);
|
|
|
|
// return mix;
|
|
// }
|
|
|
|
// private void SaveTeams(Mix mix, List<Guid> teams)
|
|
// {
|
|
// if (mix == null)
|
|
// throw new ArgumentNullException("mix");
|
|
|
|
// if (teams == null)
|
|
// teams = new List<Guid>();
|
|
|
|
// var removedTeams = new List<Team2Mix>();
|
|
// var newTeams = teams;
|
|
|
|
// if (mix.Team2Mix != null && mix.Team2Mix.Count > 0)
|
|
// {
|
|
// removedTeams = mix.Team2Mix.Where(x => !teams.Contains(x.TeamId)).ToList();
|
|
// newTeams = teams.Where(x => !mix.Team2Mix.Any(t => t.TeamId == x)).ToList();
|
|
// }
|
|
|
|
// if (removedTeams.Count > 0)
|
|
// DbContext.Team2Mix.RemoveRange(removedTeams);
|
|
|
|
// if (newTeams.Count > 0)
|
|
// {
|
|
// foreach (var team in newTeams)
|
|
// {
|
|
// DbContext.Team2Mix.Add(new Team2Mix()
|
|
// {
|
|
// Id = Guid.NewGuid(),
|
|
// MixId = mix.Id,
|
|
// TeamId = team
|
|
// });
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// private void SaveViews(Mix mix, List<Guid> views)
|
|
// {
|
|
// if (mix == null)
|
|
// throw new ArgumentNullException("mix");
|
|
|
|
// if (views == null)
|
|
// views = new List<Guid>();
|
|
|
|
// var removedViews = new List<View2Mix>();
|
|
// var newViews = views;
|
|
|
|
// if (mix.View2Mix != null && mix.View2Mix.Count > 0)
|
|
// {
|
|
// removedViews = mix.View2Mix.Where(x => !views.Contains(x.ViewId)).ToList();
|
|
// newViews = views.Where(x => !mix.View2Mix.Any(t => t.ViewId == x)).ToList();
|
|
// }
|
|
|
|
// if (removedViews.Count > 0)
|
|
// DbContext.View2Mix.RemoveRange(removedViews);
|
|
|
|
// if (newViews.Count > 0)
|
|
// {
|
|
// foreach (var view in newViews)
|
|
// {
|
|
// DbContext.View2Mix.Add(new View2Mix()
|
|
// {
|
|
// Id = Guid.NewGuid(),
|
|
// MixId = mix.Id,
|
|
// ViewId = view
|
|
// });
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// private void SaveUsers(Mix mix, List<Guid> users)
|
|
// {
|
|
// if (mix == null)
|
|
// throw new ArgumentNullException("mix");
|
|
|
|
// if (users == null)
|
|
// users = new List<Guid>();
|
|
|
|
// var removedUsers = new List<User2Mix>();
|
|
// var newUsers = users;
|
|
|
|
// if (mix.User2Mix != null && mix.User2Mix.Count > 0)
|
|
// {
|
|
// removedUsers = mix.User2Mix.Where(x => !users.Contains(new Guid(x.UserId))).ToList();
|
|
// newUsers = users.Where(x => !mix.User2Mix.Any(t => new Guid(t.UserId) == x)).ToList();
|
|
// }
|
|
|
|
// if (removedUsers.Count > 0)
|
|
// DbContext.User2Mix.RemoveRange(removedUsers);
|
|
|
|
// if (newUsers.Count > 0)
|
|
// {
|
|
// foreach (var user in newUsers)
|
|
// {
|
|
// DbContext.User2Mix.Add(new User2Mix()
|
|
// {
|
|
// Id = Guid.NewGuid(),
|
|
// MixId = mix.Id,
|
|
// UserId = user.ToString()
|
|
// });
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// public override DbSet<Mix> DataTable
|
|
// {
|
|
// get
|
|
// {
|
|
// return DbContext.Mixes;
|
|
// }
|
|
// }
|
|
|
|
// public Mix RetrieveWithRelations(Guid mixId)
|
|
// {
|
|
// if (mixId.Equals(Guid.Empty))
|
|
// return null;
|
|
|
|
// return DataTable.AsNoTracking().Include(x => x.Team2Mix)
|
|
// .Include(x => x.View2Mix)
|
|
// .Include(x => x.User2Mix)
|
|
// .FirstOrDefault(x => x.Id == mixId);
|
|
// }
|
|
|
|
// public List<MixProjectModel> GetProjectModel(DateTime startDate, DateTime endDate, List<Guid> teams, Guid userId)
|
|
// {
|
|
// var projects = new List<MixProjectModel>();
|
|
|
|
// var availableProjects = DbContext.Projects.Where(x => x.Team2Project.Any(p => teams.Contains(p.TeamId)) &&
|
|
// DbContext.VW_ProjectAccess.Any(pa => pa.UserId == userId && pa.ProjectId == x.Id && pa.Write == 1));
|
|
|
|
// var projectsModel = availableProjects.Select(x => new
|
|
// {
|
|
// Id = x.Id,
|
|
// Name = x.ParentProjectId.HasValue ? x.Name + ": " + x.ParentProject.Name : x.Name,
|
|
// Color = (x.ParentProjectId.HasValue && (x.Color == null || x.Color.Trim() == "")) ? x.ParentProject.Color : x.Color,
|
|
// Teams = x.Team2Project.Select(ts => ts.TeamId).Distinct().ToList(),
|
|
// Scenarios = x.Scenarios.Where(s => s.StartDate.HasValue && s.EndDate.HasValue && s.Type == (int)ScenarioType.Portfolio)
|
|
// .Select(s => new
|
|
// {
|
|
// Id = s.Id,
|
|
// StartDate = s.StartDate.Value,
|
|
// EndDate = s.EndDate.Value,
|
|
// Status = s.Status
|
|
// }).DefaultIfEmpty()
|
|
// }).ToList();
|
|
|
|
// foreach (var project in projectsModel)
|
|
// {
|
|
// var activeScenario = project.Scenarios.FirstOrDefault(x => x != null && x.Status == (int)ScenarioStatus.Active);
|
|
// var inactiveScenarios = project.Scenarios.Where(x => x != null && x.Status == (int)ScenarioStatus.Inactive).ToList();
|
|
|
|
// projects.Add(new MixProjectModel()
|
|
// {
|
|
// Id = project.Id,
|
|
// Name = project.Name,
|
|
// Color = string.Format("#{0}", project.Color),
|
|
// Teams = project.Teams,
|
|
// ActiveScenario = activeScenario == null ? null : new MixScenarioModel()
|
|
// {
|
|
// Id = activeScenario.Id,
|
|
// StartDate = Utils.ConvertToUnixDate(activeScenario.StartDate),
|
|
// EndDate = Utils.ConvertToUnixDate(activeScenario.EndDate)
|
|
// },
|
|
// InactiveScenarios = inactiveScenarios.Select(x => new MixScenarioModel()
|
|
// {
|
|
// Id = x.Id,
|
|
// StartDate = Utils.ConvertToUnixDate(x.StartDate),
|
|
// EndDate = Utils.ConvertToUnixDate(x.EndDate)
|
|
// }).ToList()
|
|
// });
|
|
// }
|
|
|
|
// return projects;
|
|
// }
|
|
//}
|
|
} |