Example #1
0
        public ActionResult Edit(int id)
        {
            var cRMLead = _crmLeadRepository.Get(id);

            if (cRMLead == null)
            {
                return(HttpNotFound());
            }

            // Check whether i have access to this Lead details
            var hasAccess = cRMLead.AssignedToUserId == WebUser.Id || DoIHaveCRMManageAccess();

            if (!hasAccess)
            {
                return(RedirectToAction("NotAuthorized", "Error", new { area = "" }));
            }

            var mappedTechnologies = _crmLeadTechnologyMapRepository.GetAllBy(m => m.LeadId == cRMLead.Id).Select(m => m.TechnologyId).ToList();

            ViewBag.Technologies     = new MultiSelectList(_technologyRepository.GetAll(), "Id", "Title", mappedTechnologies);
            ViewBag.AssignedToUserId = new SelectList(_userRepository.GetAll("Person"), "Id", "Person.Name", cRMLead.AssignedToUserId);
            ViewBag.LeadSourceId     = new SelectList(_crmLeadSourceRepository.GetAll(), "Id", "Title", cRMLead.LeadSourceId);
            ViewBag.CategoryId       = new SelectList(_crmLeadCategoryRepository.GetAll(), "Id", "Title", cRMLead.CategoryId);
            ViewBag.LeadSourceUserId = new SelectList(_userRepository.GetAll("Person"), "Id", "Person.Name", cRMLead.LeadSourceUserId);
            ViewBag.LeadStatusId     = new SelectList(_crmLeadStatusRepository.GetAll(), "Id", "Name", cRMLead.LeadStatusId);

            var vm = new EditCRMLeadViewModel(cRMLead);

            return(View(vm));
        }
Example #2
0
        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));
        }
Example #3
0
        public JsonResult Index()
        {
            var apiResult = TryExecute(() => _crmLeadSourceRepository.GetAll(), "Lead Sources Fetched sucessfully");

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
        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));
        }