Example #1
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var project = await _context.Projects.FirstOrDefaultAsync(m => m.Id == id);

            if (project == null)
            {
                return(NotFound());
            }

            // fill Project's entity lists
            project.Resources = await _context.ProjectResources
                                .Where(r => r.ProjectId == project.Id)
                                .OrderBy(r => r.CreatedDate)
                                .ToListAsync();

            project.Logs = await _context.ProjectLogs
                           .Include("AppUser")
                           .Where(l => l.ProjectId == project.Id)
                           .OrderByDescending(l => l.CreatedDate)
                           .ToListAsync();

            project.Risks = await _context.ProjectRisks
                            .Where(r => r.ProjectId == project.Id)
                            .ToListAsync();

            foreach (var pr in project.Risks)
            {
                pr.Risk = await _context.Risks.FindAsync(pr.RiskId);
            }

            await FillDropdownLists(project);

            ViewData["ClientId"] = new SelectList(_context.Clients.OrderBy(c => c.ClientName), "Id", "ClientName", project.ClientId);

            Project_Edit peVM = new Project_Edit
            {
                Project            = project,
                NewProjectResource = new ProjectResource(),
                EmployeeSelectList = new SelectList(_context.Employees, "Id", "EmployeeName"),
                SubSelectList      = new SelectList(_context.Subcontractors, "Id", "SubcontractorName")
            };

            CalculateFinancials(peVM);
            await _context.SaveChangesAsync();

            return(View(peVM));
        }
Example #2
0
        public JsonResult CalculateFinancials(Project_Edit peVM)
        {
            double hDone        = 0,
                   hRem         = 0,
                   oDone        = 0,
                   oRem         = 0,
                   cs           = 0,
                   cr           = 0,
                   resRevGained = 0,
                   resRev       = 0;

            // recalculate all resources
            if (peVM.Project.Resources != null)
            {
                foreach (ProjectResource res in peVM.Project.Resources)
                {
                    hDone        += res.HoursDone;
                    hRem         += res.HoursRemaining;
                    oDone        += res.OvertimeDone;
                    oRem         += res.OvertimeRemaining;
                    cs           += res.HoursDone * res.Cost;
                    cr           += res.HoursRemaining * res.Cost;
                    resRevGained += Globals.CalculateRevenue(res.HoursDone, res.OvertimeDone, res.Cost);
                    resRev       += Globals.CalculateRevenue((res.HoursDone + res.HoursRemaining), (res.OvertimeDone + res.OvertimeRemaining), res.Cost);

                    res.Revenue = Globals.CalculateRevenue(res.HoursDone, res.OvertimeDone, res.Cost);
                }
            }

            peVM.Project.HoursDone              = hDone;
            peVM.Project.HoursRemaining         = hRem;
            peVM.Project.HoursAll               = hDone + hRem;
            peVM.Project.OvertimeDone           = oDone;
            peVM.Project.OvertimeRemaining      = oRem;
            peVM.Project.OvertimeAll            = oDone + oRem;
            peVM.Project.ResourcesCostSpent     = cs;
            peVM.Project.ResourcesCostRemaining = cr;
            peVM.Project.ResourcesCost          = cs + cr;
            peVM.Project.RiskCost               = peVM.Project.RiskCostSpent + peVM.Project.RiskCostRemaining;
            peVM.Project.ResourcesRevenueGained = resRevGained;
            peVM.Project.ResourcesRevenue       = resRev;
            peVM.Project.TotalCostSpent         = cs + peVM.Project.RiskCostSpent;
            peVM.Project.TotalCostRemaining     = cr + peVM.Project.RiskCostRemaining;
            peVM.Project.TotalCost              = cs + cr + peVM.Project.RiskCostSpent + peVM.Project.RiskCostRemaining;
            peVM.Project.TotalRevenue           = resRev + peVM.Project.RiskRevenue;

            return(Json(peVM));
        }
Example #3
0
        public async Task <IActionResult> Edit(int id, Project_Edit peVM)
        {
            if (id != peVM.Project.Id)
            {
                return(NotFound());
            }

            //var errors = ModelState.Select(x => x.Value.Errors)
            //	.Where(y => y.Count > 0)
            //	.Select(a => a[0].ErrorMessage)
            //	.ToList();

            if (ModelState.IsValid)
            {
                try
                {
                    CalculateFinancials(peVM);

                    await Logging(peVM.Project);

                    _context.Update(peVM.Project);
                    await _context.SaveChangesAsync(true);

                    TempData["Toast"] = Toasts.Saved;
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProjectExists(peVM.Project.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Edit", new { id = peVM.Project.Id }));
            }

            await FillDropdownLists(peVM.Project);

            ViewData["ClientId"] = new SelectList(_context.Clients.OrderBy(c => c.ClientName), "Id", "ClientName", peVM.Project.ClientId);

            return(View(peVM));
        }