public ActionResult GetContractReport() { var allContracts = dataContext.Contract.ToList(); var lstContratcs = new List <ContractWiseReport>(); for (int i = 0; i < allContracts.Count; i++) { var con = allContracts[i]; var contractGroup = new ContractWiseReport(); contractGroup.ContractName = con.ContractName; var lstUsage = dataContext.Usage.Where(usa => usa.ContractId == con.Id).ToList(); var lstUsers = new List <ContractUserGroup>(); double?totalCost = 0; foreach (var usag in lstUsage) { var usr = new ContractUserGroup(); usr.UserName = usag.user.Name; usr.PhoneNumber = usag.PhoneNumber; usr.CompanyName = dataContext.Company.FirstOrDefault(c => c.Id == usag.CompanyId).CompanyName; usr.Cost = usag.Cost; totalCost = totalCost + usag.Cost; lstUsers.Add(usr); } contractGroup.ContractUserList = lstUsers; contractGroup.TotalCostByContract = double.Parse(totalCost.ToString()); lstContratcs.Add(contractGroup); } return(View(lstContratcs)); }
public ActionResult GetCompanyReport(int IdCompany, int IdContract, int IdUser) { if (IdUser == 0) { List <CompanyContracts> allContracts; var company = dataContext.Company.FirstOrDefault(com => com.Id == IdCompany); if (IdContract == 0) { allContracts = company.CompanyContractList.ToList(); } else { allContracts = company.CompanyContractList.Where(c => c.ContractId == IdContract).ToList(); } var lstContratcs = new List <ContractWiseReport>(); for (int i = 0; i < allContracts.Count; i++) { var con = allContracts[i]; var contractGroup = new ContractWiseReport(); contractGroup.CompanyName = company.CompanyName; contractGroup.ContractName = con.Contract.ContractName; var lstUsage = dataContext.Usage.Where(usa => usa.ContractId == con.Id).ToList(); var lstUsers = new List <ContractUserGroup>(); double?totalCost = 0; foreach (var usag in lstUsage) { var usr = new ContractUserGroup(); usr.UserName = usag.user.Name; usr.PhoneNumber = usag.PhoneNumber; usr.CompanyName = dataContext.Company.FirstOrDefault(c => c.Id == usag.CompanyId).CompanyName; usr.Cost = usag.Cost; totalCost = totalCost + usag.Cost; lstUsers.Add(usr); } contractGroup.ContractUserList = lstUsers; contractGroup.TotalCostByContract = double.Parse(totalCost.ToString()); lstContratcs.Add(contractGroup); } return(View("GetContractReport", lstContratcs)); } else { UserReportModel usrRpt = new UserReportModel(); var user = dataContext.User.FirstOrDefault(u => u.Id == IdUser); usrRpt.CompanyName = dataContext.Company.FirstOrDefault(com => com.Id == IdCompany).CompanyName; usrRpt.UserName = user.Name; double?totalCost = 0; var lstContracts = new List <UserContracts>(); foreach (var usr in user.ContractUsageList) { var ctr = new UserContracts(); ctr.ContractName = usr.Contract.ContractName; ctr.Cost = usr.Cost; totalCost = totalCost + usr.Cost; ctr.DataTransfer = usr.DataTransferInMb; ctr.Minutes = usr.Minutes; ctr.PackageUsagePercentage = usr.PackageUsagePercentage; ctr.PhoneNumber = usr.PhoneNumber; ctr.Quantity = usr.Quantity; lstContracts.Add(ctr); } usrRpt.TotalCost = totalCost; usrRpt.UserUsage = lstContracts; return(View("UserReport", usrRpt)); } }