private BusinessPlan CreateBusinessPlan(int userId, int year)
        {
            var existingPlan = _businessPlanRepository.FindBy <BusinessPlan>(b => b.UserID == userId && b.Year == year && b.DeleteDate == null).FirstOrDefault();

            if (existingPlan != null)
            {
                throw new Exception("A business plan for the given year already exists for this user.");
            }

            var plan = new BusinessPlan()
            {
                Year          = year,
                UserID        = userId,
                CreateUserID  = userId,
                CreateDate    = DateTime.Now,
                CreateDateUtc = DateTime.UtcNow,
                ModifyUserID  = userId,
                ModifyDate    = DateTime.Now,
                ModifyDateUtc = DateTime.UtcNow
            };

            // Add pre-defined Tactics to plan
            plan.Tactics.AddRange(GetPredefinedTactics(userId));

            // Add pre-defined Strategies to plan
            plan.Strategies.AddRange(GetPredefinedStrategies(userId));

            // Save it
            _businessPlanRepository.AddBusinessPlan(plan);

            // Get it back (with all the new IDs and such)
            return(_businessPlanRepository.GetBusinessPlan(userId, year));
        }
        private void CopyObjectiveAssociations(BusinessPlan plan, BusinessPlan existingPlan)
        {
            foreach (var existingObjective in existingPlan.Objectives)
            {
                var objective = plan.Objectives.Find(o => o.Name == existingObjective.Name);

                foreach (var existingStrategy in existingObjective.Strategies)
                {
                    var strategy = plan.Strategies.Find(s => s.Name == existingStrategy.Name);

                    foreach (var existingTactic in existingStrategy.Tactics)
                    {
                        var tactic = plan.Tactics.Find(t => t.Name == existingTactic.Name);

                        if (!strategy.Tactics.Contains(tactic))
                        {
                            strategy.Tactics.Add(tactic);
                        }
                    }

                    objective.Strategies.Add(strategy);
                }

                _businessPlanRepository.UpdateObjective(objective);
            }
        }
        private BusinessPlan SyncPredefinedStrategiesAndTactics(BusinessPlan plan)
        {
            var missingStrategies = GetPredefinedStrategies(plan.UserID).Where(s => plan.Strategies.All(bs => !bs.Name.Equals(s.Name, StringComparison.InvariantCultureIgnoreCase))).ToList();
            var missingTactics    = GetPredefinedTactics(plan.UserID).Where(t => plan.Tactics.All(bs => !bs.Name.Equals(t.Name, StringComparison.InvariantCultureIgnoreCase))).ToList();

            if (missingStrategies.Any() || missingTactics.Any())
            {
                foreach (var strategy in missingStrategies)
                {
                    strategy.BusinessPlanID = plan.BusinessPlanID;

                    _businessPlanRepository.AddStrategy(strategy);
                }

                foreach (var tactic in missingTactics)
                {
                    tactic.BusinessPlanID = plan.BusinessPlanID;

                    _businessPlanRepository.AddTactic(tactic);
                }

                plan = _businessPlanRepository.GetBusinessPlanById(plan.BusinessPlanID);
            }

            return(plan);
        }
        private void CopyObjectives(BusinessPlan plan, BusinessPlan existingPlan)
        {
            foreach (var existingObjective in existingPlan.Objectives)
            {
                var objective = new Objective()
                {
                    BusinessPlanID      = plan.BusinessPlanID,
                    Name                = existingObjective.Name,
                    Value               = existingObjective.Value,
                    BaselineValue       = null,
                    DataType            = existingObjective.DataType,
                    PercentComplete     = 0,
                    AutoTrackingEnabled = existingObjective.AutoTrackingEnabled,
                    CreateDate          = DateTime.Now,
                    CreateDateUtc       = DateTime.UtcNow,
                    CreateUserID        = plan.CreateUserID,
                    ModifyDate          = DateTime.Now,
                    ModifyDateUtc       = DateTime.UtcNow,
                    ModifyUserID        = plan.ModifyUserID
                };

                if (existingObjective.EstimatedCompletionDate.HasValue)
                {
                    objective.EstimatedCompletionDate = new DateTime(plan.Year, existingObjective.EstimatedCompletionDate.Value.Month, existingObjective.EstimatedCompletionDate.Value.Day);
                }

                _businessPlanRepository.AddObjective(objective);
            }
        }
Beispiel #5
0
        public ActionResult MyBusinessPlans(int?year)
        {
            var plans = _businessPlanService.GetBusinessPlans(new BusinessPlanRequest()
            {
                UserID = AssistedUser.UserID
            }).ToList();

            var businessPlan = default(BusinessPlan);

            if (year.HasValue)
            {
                businessPlan = plans.FirstOrDefault(p => p.Year == year.Value);

                if (businessPlan == null)
                {
                    throw new ArgumentException("Business Plan does not exist for given year");
                }
            }

            if (businessPlan == null)
            {
                businessPlan = plans.FirstOrDefault(p => p.Year == DateTime.Now.Year) ?? plans.FirstOrDefault();

                if (businessPlan == null)
                {
                    businessPlan = BusinessPlan.Default();
                }
            }

            var viewModel = new MyBusinessPlansViewModel
            {
                BusinessPlan = businessPlan,
                EditUrl      = Url.Action("Wizard", new { year = businessPlan.Year }),
                ExportUrl    = string.Format("/pdf/executeUrl?url={0}&title={1}%20Business%20Plan&type=BusinessPlan",
                                             Url.Action("Export", new { year = businessPlan.Year }),
                                             businessPlan.Year)
            };

            if (!plans.Any())
            {
                plans.Add(businessPlan);
            }

            foreach (var plan in plans.OrderByDescending(p => p.Year))
            {
                viewModel.PlanYears.Add(new SelectListItem
                {
                    Text  = plan.Year.ToString(),
                    Value = Url.Action("MyBusinessPlans", new { year = plan.Year })
                });
            }

            return(View("MyBusinessPlans", viewModel));
        }
Beispiel #6
0
        public JsonResult JsonUpdateBusinessPlan(BusinessPlan businessPlan)
        {
            return(JsonResponse(() =>
            {
                businessPlan.ModifyUserID = CurrentUser.UserID;
                businessPlan.ModifyDate = DateTime.Now;
                businessPlan.ModifyDateUtc = DateTime.UtcNow;

                _businessPlanService.UpdateBusinessPlan(ref businessPlan);
            }));
        }
        public int SaveBusinessPlan(string content, int id)
        {
            var biz = new BusinessPlan
            {
                content     = content,
                created_at  = DateTime.Now,
                modified_at = DateTime.Now,
                user_id     = id
            };

            _insendluEntities.BusinessPlans.Add(biz);

            return(_insendluEntities.SaveChanges());
        }
Beispiel #8
0
        public JsonResult JsonCreateBusinessPlan(int year, int?copyFromYear)
        {
            var plan = new BusinessPlan();

            if (copyFromYear.HasValue)
            {
                plan = _businessPlanService.CopyBusinessPlan(year, copyFromYear.Value, AssistedUser.UserID, CurrentUser.UserID);
            }
            else
            {
                // This will create the plan if it does not exist
                plan = _businessPlanService.GetBusinessPlan(AssistedUser.UserID, year);
            }

            return(JsonResponse(() => GetBusinessPlanWithEditorViewModel(plan)));
        }
        private void CopyEmployeeRoleAssocations(BusinessPlan plan, BusinessPlan existingPlan)
        {
            foreach (var existingRole in existingPlan.EmployeeRoles)
            {
                var role = plan.EmployeeRoles.Find(r => r.Name == existingRole.Name);

                foreach (var existingEmployee in existingRole.Employees)
                {
                    var employee = plan.Employees.FirstOrDefault(e => e.FullName == existingEmployee.FullName);

                    if (employee != null)
                    {
                        role.Employees.Add(employee);
                    }
                }

                _businessPlanRepository.UpdateEmployeeRole(role);
            }
        }
        public void AddBusinessPlan(BusinessPlan businessPlan)
        {
            var saveBusinessPlan = Context.UpdateGraph(businessPlan);

            Save();

            foreach (var tactic in businessPlan.Tactics)
            {
                tactic.BusinessPlanID = saveBusinessPlan.BusinessPlanID;
                Add(tactic);
            }

            foreach (var strategy in businessPlan.Strategies)
            {
                strategy.BusinessPlanID = saveBusinessPlan.BusinessPlanID;
                Add(strategy);
            }

            Save();
        }
        private void CopyStrategies(BusinessPlan plan, BusinessPlan existingPlan)
        {
            foreach (var existingStrategy in existingPlan.Strategies)
            {
                var strategy = new Strategy()
                {
                    BusinessPlanID = plan.BusinessPlanID,
                    Name           = existingStrategy.Name,
                    Description    = existingStrategy.Description,
                    CreateDate     = DateTime.Now,
                    CreateDateUtc  = DateTime.UtcNow,
                    CreateUserID   = plan.CreateUserID,
                    ModifyDate     = DateTime.Now,
                    ModifyDateUtc  = DateTime.UtcNow,
                    ModifyUserID   = plan.ModifyUserID
                };

                _businessPlanRepository.AddStrategy(strategy);
            }
        }
        private void CopyTactics(BusinessPlan plan, BusinessPlan existingPlan)
        {
            foreach (var existingTactic in existingPlan.Tactics)
            {
                var tactic = new Tactic()
                {
                    BusinessPlanID = plan.BusinessPlanID,
                    Name           = existingTactic.Name,
                    Description    = existingTactic.Description,
                    CreateDate     = DateTime.Now,
                    CreateDateUtc  = DateTime.UtcNow,
                    CreateUserID   = plan.CreateUserID,
                    ModifyDate     = DateTime.Now,
                    ModifyDateUtc  = DateTime.UtcNow,
                    ModifyUserID   = plan.ModifyUserID
                };

                _businessPlanRepository.AddTactic(tactic);
            }
        }
        private void CopyEmployeeRoles(BusinessPlan plan, BusinessPlan existingPlan)
        {
            foreach (var existingRole in existingPlan.EmployeeRoles)
            {
                var role = new EmployeeRole()
                {
                    BusinessPlanID = plan.BusinessPlanID,
                    Name           = existingRole.Name,
                    Description    = existingRole.Description,
                    CreateDate     = DateTime.Now,
                    CreateDateUtc  = DateTime.UtcNow,
                    CreateUserID   = plan.CreateUserID,
                    ModifyDate     = DateTime.Now,
                    ModifyDateUtc  = DateTime.UtcNow,
                    ModifyUserID   = plan.ModifyUserID
                };

                _businessPlanRepository.AddEmployeeRole(role);
            }
        }
        private void CopySwots(BusinessPlan plan, BusinessPlan existingPlan)
        {
            foreach (var existingSwot in existingPlan.Swots)
            {
                var swot = new Swot()
                {
                    BusinessPlanID = plan.BusinessPlanID,
                    Type           = existingSwot.Type,
                    Description    = existingSwot.Description,
                    CreateDate     = DateTime.Now,
                    CreateDateUtc  = DateTime.UtcNow,
                    CreateUserID   = plan.CreateUserID,
                    ModifyDate     = DateTime.Now,
                    ModifyDateUtc  = DateTime.UtcNow,
                    ModifyUserID   = plan.ModifyUserID
                };

                _businessPlanRepository.AddSwot(swot);
            }
        }
Beispiel #15
0
        private object GetBusinessPlanWithEditorViewModel(BusinessPlan businessPlan)
        {
            var editorViewModel = GetEditorViewModel();

            // Trim down biz plan (these are all fetched separately)
            businessPlan.Objectives.Clear();
            businessPlan.Strategies.Clear();
            businessPlan.Tactics.Clear();
            businessPlan.Swots.Clear();
            businessPlan.EmployeeRoles.Clear();
            businessPlan.Employees.Clear();

            return(new
            {
                EmployeeRoles = _businessPlanService.GetPreDefinedEmployeeRoles(),
                Objectives = GetPreDefinedObjectives(),
                BusinessPlan = businessPlan,
                editorViewModel.ExistingPlanYears,
                editorViewModel.AvailablePlanYears,
                selectedYear = businessPlan.Year
            });
        }
        private void PopulateObjectiveProgress(BusinessPlan plan)
        {
            if (plan.Objectives.Any())
            {
                var user = _userService.GetUserByUserId(plan.UserID);

                foreach (var objective in plan.Objectives)
                {
                    var value = user.GetMappedObjectiveProperty(objective.Name);

                    if (value != null)
                    {
                        objective.CurrentValue = value.ToString();
                    }

                    if (user.MetricsUpdateDate != DateTime.MinValue)
                    {
                        objective.CurrentValueDate = user.MetricsUpdateDate;
                    }
                }
            }
        }
        private void CopyEmployees(BusinessPlan plan, BusinessPlan existingPlan)
        {
            var list = new Dictionary <int, Employee>();

            foreach (var existingEmployee in existingPlan.Employees)
            {
                var employee = new Employee()
                {
                    BusinessPlanID = plan.BusinessPlanID,
                    FirstName      = existingEmployee.FirstName,
                    MiddleInitial  = existingEmployee.MiddleInitial,
                    LastName       = existingEmployee.LastName,
                    CreateDate     = DateTime.Now,
                    CreateDateUtc  = DateTime.UtcNow,
                    CreateUserID   = plan.CreateUserID,
                    ModifyDate     = DateTime.Now,
                    ModifyDateUtc  = DateTime.UtcNow,
                    ModifyUserID   = plan.ModifyUserID
                };

                _businessPlanRepository.AddEmployee(employee);

                // Keep track of mapping
                list.Add(existingEmployee.EmployeeID, employee);
            }

            // Re-map the parents now that we have new IDs
            foreach (var existingEmployee in existingPlan.Employees.Where(e => e.EmployeeParentID.HasValue))
            {
                var newParentEmployee = list[existingEmployee.EmployeeParentID.Value];
                var newEmployee       = list[existingEmployee.EmployeeID];

                newEmployee.EmployeeParentID = newParentEmployee.EmployeeID;

                _businessPlanRepository.Update(newEmployee);
                _businessPlanRepository.Save();
            }
        }
        public BusinessPlan CopyBusinessPlan(int year, int copyFromYear, int userId, int auditUserId)
        {
            var existingPlan = _businessPlanRepository.FindBy <BusinessPlan>(b => b.UserID == userId && b.Year == copyFromYear && b.DeleteDate == null)
                               .AsNoTracking()
                               .IncludeAll()
                               .FirstOrDefault();

            if (existingPlan != null)
            {
                // Copy core plan
                var plan = new BusinessPlan()
                {
                    Year           = year,
                    UserID         = existingPlan.UserID,
                    CreateDate     = DateTime.Now,
                    CreateDateUtc  = DateTime.UtcNow,
                    CreateUserID   = auditUserId,
                    ModifyDate     = DateTime.Now,
                    ModifyDateUtc  = DateTime.UtcNow,
                    ModifyUserID   = auditUserId,
                    MissionWhat    = existingPlan.MissionWhat,
                    MissionWhy     = existingPlan.MissionWhy,
                    MissionHow     = existingPlan.MissionHow,
                    VisionOneYear  = existingPlan.VisionOneYear,
                    VisionFiveYear = existingPlan.VisionFiveYear
                };

                using (var context = _businessPlanRepository.BeginTransaction())
                {
                    try
                    {
                        _businessPlanRepository.Add(plan);
                        _businessPlanRepository.Save();

                        // Copy Flat Data
                        CopySwots(plan, existingPlan);
                        CopyEmployees(plan, existingPlan);
                        CopyEmployeeRoles(plan, existingPlan);
                        CopyTactics(plan, existingPlan);
                        CopyStrategies(plan, existingPlan);
                        CopyObjectives(plan, existingPlan);

                        // Get a fresh plan back that has all the PKs populated
                        plan = _businessPlanRepository.GetBusinessPlanById(plan.BusinessPlanID);

                        // Now, establish the relationships
                        CopyEmployeeRoleAssocations(plan, existingPlan);
                        CopyObjectiveAssociations(plan, existingPlan);

                        context.Commit();
                    }
                    catch (Exception)
                    {
                        context.Rollback();
                        throw;
                    }
                }
            }

            // Return fresh copy
            return(GetBusinessPlan(userId, year));
        }
        public void UpdateBusinessPlan(ref BusinessPlan businessPlan)
        {
            var proxy = _businessPlanService.CreateProxy();

            proxy.UpdateBusinessPlan(ref businessPlan);
        }
 public void UpdateBusinessPlan(ref BusinessPlan businessPlan)
 {
     _businessPlanRepository.UpdateBusinessPlan(businessPlan);
 }
 public void UpdateBusinessPlan(BusinessPlan businessPlan)
 {
     Update(businessPlan);
     Save();
 }