public async Task<ActionResult> Add(ProjectAddViewModel viewModel)
        {
            Project model;
            UserProfile profile = await GetUserProfile();

            if (viewModel != null && viewModel.Project != null)
            {
                model = viewModel.Project;
            }
            else
            {
                model = new Project();
                PrepareModelForView(model);

                model.StatusCode = "T";
                model.ExpectedOrder = DateTime.Now.Date;

                viewModel = new ProjectAddViewModel();
                viewModel.Project = model;
            }

            model.CreationDate = DateTime.Now;
            model.SalesEngineer = profile.DisplayName;

            string bearerToken = cache.Get<string>("BearerToken");
            if (Request.IsAuthenticated && bearerToken == null)
            {
                var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                var _authenticationContext = new AuthenticationContext(OfficeSettings.Authority, new ADALTokenCache(signInUserId));
                var token = await OfficeIntegration.GetTokenAsync(_authenticationContext, OfficeSettings.APIResourceId);
                if (token != null)
                {
                    bearerToken = cache.Set("BearerToken", token.AccessToken);
                }
            }
            ViewBag.Token = bearerToken;
            ViewBag.ProbabilitySelector = new SelectList(new[]
            {
                new { Name = "< 25", Value = 25 },
                new { Name = "50", Value = 50 },
                new { Name = "> 90", Value = 90 }
            }, "Value", "Name");

            PrepareModelForView(viewModel.Project);
            return View(viewModel);
        }
        private double DistanceTo(Project projectA, Project projectB)
        {
            var a = projectA;
            var b = projectB;

            if (a == null || b == null)
            {
                return 1;
            }

            var ignoreFields = new List<string>()
            {
               "SalesEngineer",
                "CreationDate"
            };

            var vectorA = DocumentDistance.TrimVector(DocumentDistance.GetObjectVector(a, ignoreFields));
            var vectorB = DocumentDistance.TrimVector(DocumentDistance.GetObjectVector(b, ignoreFields));

            var distance = DocumentDistance.CalculateDistance(vectorA, vectorB);

            return distance;
        }
 private void PrepareModelForView(Project model)
 {
     model.Types = uow.ProjectTypeRepository.Get();
     model.StatusCodes = uow.ProjectStatusRepository.Get();
     model.Reasons = uow.ReasonRepository.Get();
     model.Sectors = uow.SectorRepository.Get();
 }
        public ActionResult Edit(Project model)
        {
            if (ModelState.IsValid)
            {
                uow.ProjectRepository.Update(model);
                uow.Save();
                return RedirectToAction("Detail", new { id = model.Id });
            }

            PrepareModelForView(model);

            return View(model);
        }