public JsonResult Index() { var apiResult = TryExecute(() => _requirementCategoryRepository.GetAll(), "Requirement Categories Fetched sucessfully"); return(Json(apiResult, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(NewRequirementViewModel vm) { if (ModelState.IsValid) { var requirement = new Requirement { AssignedToUserId = vm.AssignedToUserId, ContactId = vm.ContactId, SourceId = vm.SourceId, CategoryId = vm.CategoryId, Title = vm.Title, Description = vm.Description, Url = vm.Url, BillingType = vm.BillingType, Budget = vm.Budget, PostedOn = vm.PostedOn.ToUniversalTime(), RequirementStatus = RequirementStatus.New, CreatedByUserId = WebUser.Id }; _requirementRepository.Create(requirement); _unitOfWork.Commit(); // Map the Technologies if (vm.TechnologyIds != null) { foreach (var technologyId in vm.TechnologyIds) { var newMap = new RequirementTechnologyMap { RequirementId = requirement.Id, TechnologyId = technologyId }; _requirementTechnologyMapRepository.Create(newMap); } _unitOfWork.Commit(); } // Add the activities var postedActivity = new RequirementActivity { Title = "Posted in Source", Comment = "Requirement was posted", RequirementId = requirement.Id, CreatedOn = requirement.PostedOn.ToUniversalTime(), CreatedByUserId = WebUser.Id }; _requirementActivityRepository.Create(postedActivity); var createdActivity = new RequirementActivity { Title = "Created", Comment = WebUser.Name + " created the requirement in Grid", RequirementId = requirement.Id, CreatedByUserId = WebUser.Id }; _requirementActivityRepository.Create(createdActivity); _unitOfWork.Commit(); // Send Email, Email Template name is hard corded - Need to change later // Replace the hard coded emails with settings or a team. #if !DEBUG _emailComposerService.SendNewRequirementEmail(requirement.Id); #endif return(RedirectToAction("Details", "Requirements", new { id = requirement.Id })); } ViewBag.Technologies = new MultiSelectList(_technologyRepository.GetAll(), "Id", "Title", vm.TechnologyIds); ViewBag.AssignedToUserId = new SelectList(_userRepository.GetAll("Person"), "Id", "Person.Name", vm.AssignedToUserId); ViewBag.ContactId = new SelectList(_crmContactRepository.GetAll("Person"), "Id", "Person.Name", vm.ContactId); ViewBag.CategoryId = new SelectList(_requirementCategoryRepository.GetAll(), "Id", "Title", vm.CategoryId); ViewBag.SourceId = new SelectList(_crmLeadSourceRepository.GetAll(), "Id", "Title", vm.SourceId); return(View(vm)); }
public ActionResult Index() { var requirementCategories = _requirementCategoryRepository.GetAll(); return(View(requirementCategories)); }
public ActionResult Index(RequirementSearchViewModel vm) { var firstDay = DateTime.UtcNow.AddDays(-31); var lastDay = DateTime.UtcNow; ViewBag.CategoryId = new SelectList(_requirementCategoryRepository.GetAll(), "Id", "Title", vm.CategoryId); ViewBag.SourceId = new SelectList(_crmLeadSourceRepository.GetAll(), "Id", "Title", vm.SourceId); Func <IQueryable <Requirement>, IQueryable <Requirement> > requirementFilter = q => { if (vm.SourceId.HasValue) { q = q.Where(r => r.SourceId == vm.SourceId.Value); } if (vm.CategoryId.HasValue) { q = q.Where(r => r.CategoryId == vm.CategoryId.Value); } if (vm.Status.HasValue) { q = q.Where(r => r.RequirementStatus == vm.Status.Value); } if (vm.StartDate.HasValue) { q = q.Where(r => r.CreatedOn >= vm.StartDate.Value); firstDay = vm.StartDate.Value; } if (vm.EndDate.HasValue) { q = q.Where(r => r.CreatedOn <= vm.EndDate.Value); lastDay = vm.EndDate.Value; } return(q); }; vm.Total = _requirementRepository.Count(); Func <IQueryable <Requirement>, IQueryable <Requirement> > postedRequirementFilter = q => { q = q.Where(r => r.CreatedOn >= firstDay && r.PostedOn != null); return(requirementFilter(q)); }; Func <IQueryable <Requirement>, IQueryable <Requirement> > closedRequirementFilter = q => { q = q.Where(r => r.CreatedOn >= firstDay && r.RequirementStatus == RequirementStatus.Won); return(requirementFilter(q)); }; Func <IQueryable <Requirement>, IQueryable <Requirement> > lostRequirementFilter = q => { q = q.Where(r => r.CreatedOn >= firstDay && r.RequirementStatus == RequirementStatus.Lost); return(requirementFilter(q)); }; var postedRequirements = _requirementRepository.Search(postedRequirementFilter) .ToList() .GroupBy(r => r.CreatedOn.ToShortDateString()) .Select(r => new { Day = r.Key, Total = r.Count() }); var closedRequirements = _requirementRepository.Search(closedRequirementFilter) .ToList() .GroupBy(r => r.CreatedOn.ToShortDateString()) .Select(r => new { Day = r.Key, Total = r.Count() }); var lostRequirements = _requirementRepository.Search(lostRequirementFilter) .ToList() .GroupBy(r => r.CreatedOn.ToShortDateString()) .Select(r => new { Day = r.Key, Total = r.Count() }); var dateArray = new List <string> { "x" }; var postedArray = new List <string> { "new" }; var closedArray = new List <string> { "won" }; var lostArray = new List <string> { "lost" }; var counter = firstDay; while (counter <= lastDay) { var selectedDay = counter.ToShortDateString(); dateArray.Add(selectedDay); var selectedPost = postedRequirements.FirstOrDefault(p => p.Day == selectedDay); postedArray.Add(selectedPost?.Total.ToString() ?? "0"); var selectedClosed = closedRequirements.FirstOrDefault(p => p.Day == selectedDay); closedArray.Add(selectedClosed != null ? selectedClosed.Total.ToString() : "0"); var selectedLost = lostRequirements.FirstOrDefault(p => p.Day == selectedDay); lostArray.Add(selectedLost != null ? selectedLost.Total.ToString() : "0"); counter = counter.AddDays(1); } ViewBag.Dates = dateArray; ViewBag.Posts = postedArray; ViewBag.Closed = closedArray; ViewBag.Lost = lostArray; return(View(vm)); }