public void CreateHourCosts(Project project, Project similarProject)
        {
            using (var context = new ScrumFactoryEntities(this.connectionString)) {

                // get similar costs
                RoleHourCost[] similarCosts = null;
                if(similarProject!=null)
                    similarCosts = GetHourCosts(similarProject.ProjectUId);

                // fore each role at this project
                foreach (Role r in project.Roles) {

                    // checks if there is a role with the same shortname at the similar project, and if so, uses its costs
                    Role similarRole = null;
                    string roleName = r.RoleShortName.ToLower();
                    if(similarProject!=null)
                       similarRole = similarProject.Roles.FirstOrDefault(sr => sr.RoleShortName.ToLower() == roleName);

                    RoleHourCost similarHourCost = null;
                    if(similarRole!=null && similarCosts!=null)
                        similarHourCost = similarCosts.FirstOrDefault(c => c.RoleUId == similarRole.RoleUId);
                    if(similarHourCost==null)
                        similarHourCost = new RoleHourCost() { Price = 0, Cost = 0 };

                    // only if role is new
                    RoleHourCost oldCost = context.RoleHourCosts.SingleOrDefault(h => h.RoleUId == r.RoleUId);
                    if (oldCost == null) {
                        RoleHourCost cost = new RoleHourCost() { RoleUId = r.RoleUId, ProjectUId = project.ProjectUId, Cost = similarHourCost.Cost, Price = similarHourCost.Price };
                        context.RoleHourCosts.AddObject(cost);
                    }

                }
                context.SaveChanges();
            }
        }
 private void SaveHourCost(RoleHourCost cost, ScrumFactoryEntities context)
 {
     RoleHourCost oldCost = context.RoleHourCosts.SingleOrDefault(c => c.RoleUId == cost.RoleUId);
     if (oldCost == null) {
         context.RoleHourCosts.AddObject(cost);
         return;
     }
     context.AttachTo("RoleHourCosts", oldCost);
     context.ApplyCurrentValues<RoleHourCost>("RoleHourCosts", cost);
 }
 public void SaveHourCosts(RoleHourCost[] costs)
 {
     using (var context = new ScrumFactoryEntities(this.connectionString)) {
         foreach (RoleHourCost cost in costs)
             SaveHourCost(cost, context);
         context.SaveChanges();
     }
 }
 public decimal GetProjectTasksPrice(RoleHourCost[] costs)
 {
     throw new NotImplementedException();
 }
 public void UpdateHourCosts(string projectUId, RoleHourCost[] hourCosts)
 {
     var client = ClientHelper.GetClient(authorizationService);
     HttpResponseMessage response = client.Put(Url("ProjectRoleHoursCosts/" + projectUId + "/"), new ObjectContent<RoleHourCost[]>(hourCosts, JsonMediaTypeFormatter.DefaultMediaType));
     ClientHelper.HandleHTTPErrorCode(response);
 }
        public void UpdateHourCosts(string projectUId, RoleHourCost[] hourCosts)
        {
            // verifies permission
            authorizationService.VerifyPermissionAtProject(projectUId, PermissionSets.SCRUM_MASTER);
            authorizationService.VerifyCanSeeProposalValues();

            // save new costs
            proposalsRepository.SaveHourCosts(hourCosts);

            // updates the project proposals with new total price
            ICollection<BacklogItem> backlog = backlogservice.GetCurrentBacklog(projectUId, (short)BacklogFiltersMode.ALL);
            ICollection<Proposal> proposals = GetProjectProposals(projectUId);
            foreach (Proposal p in proposals.Where(p => p.ProposalStatus == (short)ProposalStatus.PROPOSAL_WAITING)) {
                Proposal pWithItems = GetProjectProposal(projectUId, p.ProposalUId);
                pWithItems.SetBacklogItems(backlog);
                pWithItems.TotalValue = pWithItems.CalcTotalPrice(hourCosts);
                proposalsRepository.SaveProposal(pWithItems);
            }
        }
 public decimal GetProjectTasksPrice(RoleHourCost[] costs)
 {
     decimal price = 0;
     foreach (RoleHourCost roleCost in costs) {
         decimal hours = tasksRepository.GetTotalEffectiveHoursByRole(roleCost.RoleUId);
         price = price + hours * roleCost.Price;
     }
     return price;
 }