Ejemplo n.º 1
0
        /// <summary>
        /// Get the opportunities for client
        /// </summary>
        /// <param name="clientID">The Client ID</param>
        /// <param name="opportunityName">The opportunity name</param>
        /// <param name="companyName">The company name</param>
        /// <param name="owner">The owner</param>
        /// <param name="opportunityStatus">The opportunity status</param>
        /// <returns></returns>
        public Response GetOpportunities(int clientID, string oppId, string opportunityName, string companyName, string owner, string opportunityStatus)
        {
            var response      = new Response();
            var opportunityBL = new OpportunityBL();

            List <OpportunityDto> opportunities = opportunityBL.GetOpportunities(clientID, oppId, opportunityName, companyName, owner, opportunityStatus);

            response.Results.Add("Success");

            List <SearchOpportunityDto> searchOpportunities = opportunities.Select(opp => new SearchOpportunityDto
            {
                OppID          = opp.OppID,
                CRMOppID       = opp.CRMOppID,
                OppName        = opp.OppName,
                CompanyName    = opp.CompanyName,
                OppStatus      = opp.OppStatus.HasValue ? opp.OppStatus.Value.ToString() : string.Empty,
                OppStatusName  = opp.OppStatusName,
                OppProbability = opp.OppProbability.HasValue ? opp.OppProbability.Value.ToString() : string.Empty,
                OppCloseDate   = opp.OppCloseDate,
                OppOwner       = opp.OppOwner,
                OppOwnerName   = opp.OppOwnerName
            }).ToList();

            string userSerialize = JsonConvert.SerializeObject(searchOpportunities);

            response.Results.Add(userSerialize);

            return(response);
        }
Ejemplo n.º 2
0
        public JsonResult OpportunityDataGrid()
        {
            ///////////////////////////////////////////////////////////////////
            //First get users list
            var liUsers = new List <UserDto>();

            if (_authUser.ManagerUserID.HasValue && _authUser.ManagerUserID.Value != 0)
            {
                var userWManagers = _userBl.GetUsersWithManager(_authUser.ClientId);

                var tUser = userWManagers.SingleOrDefault(u => u.UserId == _authUser.UserId);
                liUsers.Add(tUser);

                var firstLevel = userWManagers.Where(u => u.ManagerUserID == _authUser.UserId).ToList();
                if (firstLevel.Count > 0)
                {
                    liUsers.AddRange(firstLevel);
                    // userWManagers.RemoveAll(x => !liUsers.Any(y => y.UserId == x.UserId));

                    Utils.GetUsers(userWManagers, liUsers);
                }
            }
            else
            {
                liUsers = _userBl.GetUsers(_authUser.ClientId);
            }
            ////////////////////////////////////////////////////////////////////


            Mapper.CreateMap <UserDto, UserModel>()
            .ForMember(dest => dest.ManagerUserID, opt => opt.MapFrom(src => src.ManagerUserID ?? 0))
            .ForMember(dest => dest.ManagerUserName, opt => opt.MapFrom(src => "-------"));
            var peopleVm = Mapper.Map <List <UserDto>, List <UserModel> >(liUsers);

            //Mapper.AssertConfigurationIsValid();

            foreach (var userModel in peopleVm.Where(userModel => userModel.ManagerUserID != null))
            {
                userModel.ManagerUserName =
                    liUsers.Where(u => u.UserId == userModel.ManagerUserID)
                    .Select(u => u.FirstName + " " + u.LastName).FirstOrDefault();
            }

            //Get opportunities for specific client
            var nList = _opportunityBl.GetOpportunities(_authUser.ClientId);

            //Get opportunity statuses for specific client
            var statuses = _utilityBL.GetStatuses(_authUser.ClientId);

            var displayOpps = (from opportunityDto in nList
                               join stat in statuses on opportunityDto.OppStatus ?? 0 equals stat.ID
                               join user in peopleVm on opportunityDto.OppOwner equals user.UserId
                               select new OpportunityModel
            {
                CRMOppID = opportunityDto.CRMOppID,
                ClientID = opportunityDto.ClientID,
                CloudLastUpdDT = opportunityDto.CloudLastUpdDT,
                CompanyName = opportunityDto.CompanyName,
                NumofQuotes = opportunityDto.NumofQuotes,
                OppCloseDate = opportunityDto.OppCloseDate,
                OppID = opportunityDto.OppID,
                OppName = opportunityDto.OppName,
                OppProbability = opportunityDto.OppProbability,
                OppStatusId = stat.ID,
                OppStatusName = stat.OppStatus,
                StageType = stat.StageType,
                SDALastUpdDT = opportunityDto.SDALastUpdDT,
                OppOwner = opportunityDto.OppOwner,
                OppOwnerName = user.FirstName + " " + user.LastName,
                Manager = user.ManagerUserName,
                QuotedAmount = opportunityDto.QuotedAmount,
                QuotedCost = opportunityDto.QuotedCost,
                QuotedMargin = opportunityDto.QuotedMargin,
                CreateDT = opportunityDto.CreateDT,
                ClientDefinedTotal1 = opportunityDto.ClientDefinedTotal1,
                ClientDefinedTotal2 = opportunityDto.ClientDefinedTotal2,
                ClientDefinedTotal3 = opportunityDto.ClientDefinedTotal3,
                ClientDefinedTotal4 = opportunityDto.ClientDefinedTotal4,
                ClientDefinedTotal5 = opportunityDto.ClientDefinedTotal5,
                ClientDefinedTotal6 = opportunityDto.ClientDefinedTotal6,
                ClientDefinedTotal7 = opportunityDto.ClientDefinedTotal7,
                ClientDefinedTotal8 = opportunityDto.ClientDefinedTotal8,
                ClientDefinedTotal9 = opportunityDto.ClientDefinedTotal9,
                ClientDefinedTotal10 = opportunityDto.ClientDefinedTotal10,
                ClientDefinedText1 = opportunityDto.ClientDefinedText1,
                ClientDefinedText2 = opportunityDto.ClientDefinedText2,
                ClientDefinedText3 = opportunityDto.ClientDefinedText3,
                ClientDefinedText4 = opportunityDto.ClientDefinedText4,
                ClientDefinedText5 = opportunityDto.ClientDefinedText5
            });

            return(Json(displayOpps, JsonRequestBehavior.AllowGet));
        }