/// <summary> /// This method will return list of software allocated to selected system /// </summary> /// <param name="objSoftware">Object containing SystemAllocationId</param> /// <returns>Returns a list of software details</returns> public List <SoftwareDetailsVm> ShowEmployeeSoftwareDetails(SoftwareDetailsVm objSoftware) { using (Data.Model.LicenseManagementMVCEntities DbContext = new LicenseManagementMVCEntities()) { var results = from s in DbContext.Softwares join st in DbContext.SoftwareTypes on s.SoftwareTypeId equals st.SoftwareTypeId join p in DbContext.Products on s.ProductId equals p.ProductId join l in DbContext.Licenses on s.SoftwareId equals l.SoftwareId join si in DbContext.SystemInstallations on l.LicenseId equals si.LicenseId join sa in DbContext.SystemAllocations on si.SystemAllocationId equals sa.SystemAllocationId where sa.SystemAllocationId == objSoftware.SystemAllocationId select new { product = p.ProductName, software = s.SoftwareName, type = st.SoftwareTypeName, allotedDate = si.InstallationDate, releaseDate = si.ReleaseDate, softwareId = s.SoftwareId, systemInstallationId = si.SystemInstallationId }; SoftwareDetailsVm objSoftwareDetails = new SoftwareDetailsVm(); List <SoftwareDetailsVm> softwareList = new List <SoftwareDetailsVm>(); foreach (var s in results) { objSoftwareDetails = new SoftwareDetailsVm() { ProductName = s.product, SoftwareName = s.software, AllotedDate = s.allotedDate, SoftwareType = s.type, ReleaseDate = s.releaseDate, SoftwareId = s.softwareId, SystemInstallationId = s.systemInstallationId }; softwareList.Add(objSoftwareDetails); } return(softwareList); } }
/// <summary> /// This method will accept the SoftwareId as paramter and displays the respective software details /// </summary> /// <param name="objSoftware">Object holding SoftwareId of selected software</param> /// <returns>The object holding all the details to be displayed on screen</returns> public SoftwareDetailsVm ShowSoftwareDetails(BusinessEntities.Software objSoftware) { using (Data.Model.LicenseManagementMVCEntities DbContext = new LicenseManagementMVCEntities()) { var result = (from s in DbContext.Softwares join p in DbContext.Products on s.ProductId equals p.ProductId join st in DbContext.SoftwareTypes on s.SoftwareTypeId equals st.SoftwareTypeId where s.SoftwareId == objSoftware.SoftwareId select new { ProductName = p.ProductName, ProductId = p.ProductId, SoftwareName = s.SoftwareName, SoftwareId = s.SoftwareId, SoftwareType = st.SoftwareTypeName, SoftwareTypeId = st.SoftwareTypeId }).FirstOrDefault(); SoftwareDetailsVm objSoft = new SoftwareDetailsVm(); if (result != null) { objSoft.SoftwareId = result.SoftwareId; objSoft.ProductName = result.ProductName; objSoft.SoftwareType = result.SoftwareType; objSoft.SoftwareName = result.SoftwareName; objSoft.SoftwareTypeId = result.SoftwareTypeId; objSoft.ProductId = result.ProductId; } var totalLicense = from l in DbContext.Licenses where l.SoftwareId == objSoftware.SoftwareId group l by l.SoftwareId into grp select new { totalCount = grp.Sum(x => x.LicenseCount) }; foreach (var q in totalLicense) { objSoft.TotalCount = q.totalCount; } int allocatedCount = (from l in DbContext.Licenses join si in DbContext.SystemInstallations on l.LicenseId equals si.LicenseId where l.SoftwareId == objSoftware.SoftwareId select l).Count(); objSoft.AllocatedCount = allocatedCount; var lastAllocation = (from l in DbContext.Licenses join si in DbContext.SystemInstallations on l.LicenseId equals si.LicenseId join sa in DbContext.SystemAllocations on si.SystemAllocationId equals sa.SystemAllocationId join e in DbContext.Employees on sa.EmployeeId equals e.EmployeeId where l.SoftwareId == objSoftware.SoftwareId select new { firstName = e.FirstName, lastName = e.LastName, empNo = e.EmployeeId }); foreach (var la in lastAllocation) { objSoft.EmployeeName = la.firstName + " " + la.lastName; objSoft.EmployeeId = la.empNo; } return(objSoft); } }