public async Task GetAllTest()
        {
            // Arrange
            var client = SetupMock_Skill();
            var config = new Mock <IConfiguration>();

            client.BaseAddress = new Uri("https://localhost:1111/");
            config.SetupGet(s => s["SkillsURL"]).Returns("https://localhost:1111/");
            var service = new SkillService(null, new NullLogger <SkillService>(), config.Object)
            {
                Client = client
            };

            // Act
            var result = await service.GetAll();

            // Assert
            Assert.IsNotNull(result);
            foreach (var skill in result)
            {
                var testItem = TestData.Skills().FirstOrDefault(s => s.Id == skill.Id);
                Assert.AreEqual(testItem.Name, skill.Name);
                Assert.AreEqual(testItem.XpCost, skill.XpCost);
            }
        }
Example #2
0
        public JsonResult GetSkillByGroup(Guid groupID)
        {
            try
            {
                #region " [ Declaration ] "

                SkillService _service = new SkillService();

                #endregion

                #region " [ Main processing ] "

                var model = _service.GetAll(groupID, UserID);

                #endregion

                return(this.Json(model, JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException serviceEx)
            {
                throw serviceEx;
            }
            catch (DataAccessException accessEx)
            {
                throw accessEx;
            }
            catch (Exception ex)
            {
                throw new ControllerException(FILE_NAME, "GetSkillByGroup", UserID, ex);
            }
        }
Example #3
0
        public ResultViewModel <IEnumerable <SkillViewModel> > GetList(int pageIndex, int pageSize = 20)
        {
            ResultViewModel <IEnumerable <SkillViewModel> > result
                = new ResultViewModel <IEnumerable <SkillViewModel> >();
            int count = 0;

            try
            {
                var Skills = skillService.GetAll(out count, 0, pageIndex, pageSize);
                result.Successed = true;
                result.Data      = Skills;
            }
            catch (Exception ex)
            {
                result.Successed = false;
                result.Message   = "Something Went Wrong !!";
            }
            return(result);
        }
Example #4
0
        public ResultViewModel <IEnumerable <SkillViewModel> > GetAllSkills()
        {
            ResultViewModel <IEnumerable <SkillViewModel> > result =
                new ResultViewModel <IEnumerable <SkillViewModel> >();

            try
            {
                result.Data      = skillService.GetAll();
                result.Message   = "Skills gotten succesfuly";
                result.Successed = true;
            }
            catch
            {
                result.Message   = "Something went wrong!!";
                result.Successed = false;
            }
            return(result);
        }
Example #5
0
        public ActionResult Index()
        {
            try
            {
                #region " [ Declaration ] "

                SkillGroupService _groupService = new SkillGroupService();
                SkillService      _skillService = new SkillService();

                ViewBag.groupID = "";
                ViewBag.skills  = null;

                #endregion

                #region " [ Main processing ] "

                var model = _groupService.GetAll(UserID);


                if (model.Count > 0)
                {
                    ViewBag.groupID = model[0].ID.ToString();
                    ViewBag.skills  = _skillService.GetAll(model[0].ID, UserID);
                }

                #endregion

                return(View(model));
            }
            catch (ServiceException serviceEx)
            {
                throw serviceEx;
            }
            catch (DataAccessException accessEx)
            {
                throw accessEx;
            }
            catch (Exception ex)
            {
                throw new ControllerException(FILE_NAME, "Index", UserID, ex);
            }
        }
Example #6
0
        //public static string CallRestMethod(string url)
        //{
        //    try
        //    {
        //        HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
        //        webrequest.Method = "GET";
        //        webrequest.ContentType = "application/json";
        //        webrequest.Headers.Add("Username", "ssa");
        //        webrequest.Headers.Add("Password", "se62036@123");
        //        HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
        //        Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
        //        StreamReader responseStream = new StreamReader(webresponse.GetResponseStream(), enc);
        //        string result = string.Empty;
        //        result = responseStream.ReadToEnd();
        //        webresponse.Close();
        //        return result;
        //    }
        //    catch (Exception e)
        //    {
        //        return e.ToString();
        //    }
        //}

        public static void UpdateSeniority()
        {
            SkillService skillService = new SkillService();
            var          skills       = skillService.GetAll();
            var          now          = DateTime.UtcNow.AddHours(7);
            var          first        = now.Date.AddDays(-(now.Date.Day - 1));
            var          last         = first.AddMonths(1).AddTicks(-1);

            while (now != last)
            {
                var minutesToSleep = (int)(new DateTime(last.Year, last.Month, last.Day, 0, 0, 0) - DateTime.Now).TotalMinutes;
                Thread.Sleep(minutesToSleep);
            }

            foreach (var skillItem in skills)
            {
                if (skillItem.MonthExperience != null)
                {
                    skillItem.MonthExperience++;
                }
                skillService.Update(skillItem);
            }
        }
Example #7
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()
                });
            }
        }
Example #8
0
 public IEnumerable <SkillDTO> GetSkills()
 {
     return(skillService.GetAll());
 }