private void InitializeViewBagForAnnouncement()
        {
            var agencies          = AgencyService.GetAll();
            var announcementTypes = AnnouncementTypeService.GetAll();

            ViewBag.Agencies          = new SelectList(agencies, "Id", "Name");
            ViewBag.AnnouncementTypes = new SelectList(announcementTypes, "Id", "Name");
        }
示例#2
0
        public static ResponseObject <int> FindITSupporterByRequestId(int requestId)
        {
            try
            {
                var requestService     = new RequestService();
                var itSupporterService = new ITSupporterService();
                var agencyService      = new AgencyService();
                var comService         = new CompanyService();
                var skillService       = new SkillService();
                var serviceItemService = new ServiceItemService();

                var request            = requestService.GetAll().SingleOrDefault(p => p.RequestId == requestId);
                var serviceItemId      = request.ServiceItemId;
                var serviceITSupportId = serviceItemService.GetAll().SingleOrDefault(p => p.ServiceItemId == serviceItemId).ServiceITSupportId;
                var skills             = skillService.GetAll().Where(a => a.ServiceITSupportId == serviceITSupportId);
                var agency             = agencyService.GetAll().SingleOrDefault(p => p.AgencyId == request.AgencyId);
                var company            = comService.GetAll().SingleOrDefault(p => p.CompanyId == agency.CompanyId);;
                List <RenderITSupporterListWithWeight> itSupporterListWithWeights = new List <RenderITSupporterListWithWeight>();
                foreach (var item in skills)
                {
                    var itSupporter = itSupporterService.GetAll().SingleOrDefault(p => p.ITSupporterId == item.ITSupporterId && p.IsBusy == false && p.IsOnline == true);
                    if (itSupporter != null)
                    {
                        double weightForITSupporter = 0;
                        var    a = requestService.GetAll().Where(p => p.CurrentITSupporter_Id == itSupporter.ITSupporterId && p.AgencyId == request.AgencyId).Count();
                        var    weightForITSupporterFamiliarWithAgency = a * ((company.PercentForITSupporterFamiliarWithAgency != null && company.PercentForITSupporterFamiliarWithAgency.Value != 0) ? company.PercentForITSupporterFamiliarWithAgency.Value : 30);
                        var    weightForITSupporterRate = (itSupporter.RatingAVG ?? 0) * ((company.PercentForITSupporterRate != null && company.PercentForITSupporterRate.Value != 0) ? company.PercentForITSupporterRate.Value : 40);
                        var    weightForITSupporterExp  = (item.MonthExperience ?? 0) * ((company.PercentForITSupporterExp != null && company.PercentForITSupporterExp.Value != 0) ? company.PercentForITSupporterExp.Value : 30);
                        weightForITSupporter = weightForITSupporterFamiliarWithAgency + weightForITSupporterRate + weightForITSupporterExp;
                        var renderITSupporterListWithWeight = new RenderITSupporterListWithWeight()
                        {
                            ITSupporterId         = itSupporter.ITSupporterId,
                            ITSupporterName       = itSupporter.ITSupporterName,
                            ITSupporterListWeight = weightForITSupporter,
                            TimesReject           = 0
                        };
                        itSupporterListWithWeights.Add(renderITSupporterListWithWeight);
                    }
                }
                // Add redis
                itSupporterListWithWeights = itSupporterListWithWeights.OrderByDescending(p => p.ITSupporterListWeight).ToList();
                //MemoryCacher memoryCacher = new MemoryCacher();
                //memoryCacher.Add("ITSupporterListWithWeights", itSupporterListWithWeights, DateTimeOffset.UtcNow.AddHours(1));
                Queue <RenderITSupporterListWithWeight> itSupporterListWithWeightQueue = new Queue <RenderITSupporterListWithWeight>(itSupporterListWithWeights);

                RedisTools redisTools = new RedisTools();
                redisTools.Save("ITSupporterListWithWeights", itSupporterListWithWeightQueue);
                // Get first
                var itSupporterNameFound = itSupporterListWithWeights.FirstOrDefault().ITSupporterName;
                int itSupporterIdFound   = itSupporterListWithWeights.FirstOrDefault().ITSupporterId;
                if (itSupporterIdFound > 0)
                {
                    return(new ResponseObject <int> {
                        IsError = false, SuccessMessage = $"Tìm được Hero {itSupporterNameFound}! Vùi lòng đợi xác nhận", ObjReturn = itSupporterIdFound
                    });
                }
                return(new ResponseObject <int> {
                    IsError = true, WarningMessage = "Chưa tìm được Hero nào thích hợp!"
                });
            }
            catch (Exception ex)
            {
                return(new ResponseObject <int> {
                    IsError = true, WarningMessage = "Chưa tìm được Hero nào thích hợp!", ErrorMessage = ex.ToString()
                });
            }
        }