public String DeleteGC(GroupCompanyModel gcmodel) { Company company = CompanyRepository.Companys.SingleOrDefault(c => c.CompanyId == gcmodel.CompanyId); //int deletecostbreakup = Task.Run<int>(async () => await CostBreakupRepository.DeleteCostBreakup(costbreakup.CBID)).Result; //int deleteproject = Task.Run<int>(async () => await ProjectRepository.DeleteProject(gcpmodel.ProjectId)).Result; //int countprojects = ProjectRepository.Projects.Count(p => p.CompanyId == gcpmodel.CompanyId); //if (countcompany == 0) //{ // int deleteCompany = Task.Run<int>(async () => await CompanyRepository.DeleteCompany(gcpmodel.CompanyId)).Result; //} IEnumerable <Project> projects = ProjectRepository.Projects.Where(p => p.CompanyId == company.CompanyId && p.GroupId == company.GroupId); foreach (Project project in projects) { Task.Run(async() => await ProjectRepository.DeleteProject(project.ProjectId)); CostBreakup costbreakup = CostBreakupRepository.CostBreakups.SingleOrDefault(c => c.ProjectID == project.ProjectId); Task.Run(async() => await CostBreakupRepository.DeleteCostBreakup(costbreakup.CBID)); } int deletecompany = Task.Run <int>(async() => await CompanyRepository.DeleteCompany(company.CompanyId)).Result; int countgroup = CompanyRepository.Companys.Count(c => c.GroupId == gcmodel.GroupId); if (countgroup == 0) { int deleteGroup = Task.Run <int>(async() => await GroupRepository.DeleteGroup(gcmodel.GroupId)).Result; } //Project project = ProjectRepository.Projects.FirstOrDefault(p => p.ProjectId == gcpmodel.ProjectId); return(deletecompany > 0 ? "Successfully Deleted Group" : "Deletion failed"); }
public async Task <int> AddCostBreakup(CostBreakup CostBreakup) { db.CostBreakups.Add(CostBreakup); int result = await db.SaveChangesAsync(); return(result); }
public async Task <string> UpdateCostBreakup(CostBreakup costBreakup) { decimal totalcost = 0; CostBreakup existingcostBreakup = CostBreakupRepository.GetCostBreakups().SingleOrDefault(c => c.CBID == costBreakup.CBID); if (existingcostBreakup == default(CostBreakup)) { return("CostBreakup doesn't exist"); } Project existingproject = ProjectRepository.Projects.SingleOrDefault(p => p.ProjectId == costBreakup.ProjectID); totalcost = costBreakup.LandSiteCost.GetValueOrDefault() + costBreakup.SolarModules.GetValueOrDefault() + costBreakup.ModuleMountStruct.GetValueOrDefault() + costBreakup.PowerCondUnit.GetValueOrDefault() + costBreakup.EvacuationCost.GetValueOrDefault() + costBreakup.Preoperativeexp.GetValueOrDefault() + costBreakup.Contingency.GetValueOrDefault() + costBreakup.IDC.GetValueOrDefault() + costBreakup.FinancingCost.GetValueOrDefault() + costBreakup.Workingcapital.GetValueOrDefault() + costBreakup.Dsra.GetValueOrDefault(); costBreakup.TotalCost = totalcost; existingproject.TotalCost = totalcost; int updatecostBreakup = await CostBreakupRepository.UpdateCostBreakup(costBreakup); int updateproject = await ProjectRepository.UpdateProject(existingproject); return(updatecostBreakup > 0 ? "Successfully updated CostBreakup" : "Updation failed"); }
public async Task <int> DeleteCostBreakup(int cbid) { CostBreakup CostBreakup = await FetchbyCostBreakupId(cbid); db.CostBreakups.Remove(CostBreakup); int result = await db.SaveChangesAsync(); return(result); }
public IHttpActionResult UpdateCostBreakup(CostBreakup costbreakup) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } string message = Task.Run <string>(async() => await _costbreakup.UpdateCostBreakup(costbreakup)).Result; return(Ok(message)); }
public CostBreakup GetCostBreakupbyProjectId(int?id) { if (id == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } CostBreakup costbreakup = _costbreakup.GetCostBreakupbyProjectId((int)id); return(costbreakup); }
public async Task <int> UpdateCostBreakup(CostBreakup CostBreakup) { CostBreakup existingCostBreakup = await FetchbyCostBreakupId(CostBreakup.CBID); db.Entry(existingCostBreakup).State = EntityState.Detached; db.Entry(CostBreakup).State = EntityState.Modified; int result = await db.SaveChangesAsync(); return(result); }
public string DeleteProject(int projectId) { CostBreakup costbreakup = CostBreakupRepository.CostBreakups.SingleOrDefault(c => c.ProjectID == projectId); int deletecostbreakup = Task.Run <int>(async() => await CostBreakupRepository.DeleteCostBreakup(costbreakup.CBID)).Result; Project project = ProjectRepository.Projects.SingleOrDefault(p => p.ProjectId == projectId); int deleteproject = Task.Run <int>(async() => await ProjectRepository.DeleteProject(projectId)).Result; return(deleteproject > 0 ? "Successfully Deleted Project" : "Deletion failed"); }
public CostBreakup GetCostBreakupbyProjectId(int projectId) { CostBreakup costbreakup = CostBreakupRepository.GetCostBreakups().SingleOrDefault(p => p.ProjectID == projectId); return(costbreakup); }
public async Task <CostBreakup> FetchbyCostBreakupId(int cbid) { CostBreakup CostBreakup = await db.CostBreakups.FindAsync(cbid); return(CostBreakup); }