public async Task AddAgencyToDb_When_ValidGlobalAgencyRegionLabel_And_ChanginGlobalAgencyForBU_Should_UpdateGlobalAgencyOfAgency() { // Arrange var agencyName = "Saatchi"; var regionName = "Japan"; var globalAgencyRegionLabel = $"{Constants.BusinessUnit.GlobalAgencyRegionLabelPrefix}{agencyName}_{regionName}"; var a5Agency = await PrepareTestData(globalAgencyRegionLabel); var existingGlobalAgencyRegion = new GlobalAgencyRegion { Region = regionName, GlobalAgency = new GlobalAgency { Name = "Any other global agency" } }; var costAgency = EFContext.Agency.First(); costAgency.GlobalAgencyRegion = existingGlobalAgencyRegion; EFContext.GlobalAgencyRegion.Add(existingGlobalAgencyRegion); EFContext.SaveChanges(); // Act await AgencyService.AddAgencyToDb(a5Agency); // Assert EFContext.GlobalAgency.Should().HaveCount(2); EFContext.GlobalAgencyRegion.Should().HaveCount(2); costAgency.GlobalAgencyRegion.Region.Should().Be(regionName); costAgency.GlobalAgencyRegion.GlobalAgency.Name.Should().Be(agencyName); }
public async Task AddAgencyToDb_When_ValidGlobalAgencyRegionLabel_And_ExistingGlobalAgency_Should_AddGlobalAgencyRegion() { // Arrange var agencyName = "Saatchi"; var regionName = "Japan"; var globalAgencyRegionLabel = $"{Constants.BusinessUnit.GlobalAgencyRegionLabelPrefix}{agencyName}_{regionName}"; var a5Agency = await PrepareTestData(globalAgencyRegionLabel); var costAgency = EFContext.Agency.First(); var existingGlobalAgencyRegion = new GlobalAgencyRegion { Region = "North America", GlobalAgency = new GlobalAgency { Name = agencyName } }; costAgency.GlobalAgencyRegion = existingGlobalAgencyRegion; EFContext.GlobalAgencyRegion.Add(existingGlobalAgencyRegion); EFContext.SaveChanges(); // Act await AgencyService.AddAgencyToDb(a5Agency); // Assert EFContext.GlobalAgency.Should().HaveCount(1); EFContext.GlobalAgencyRegion.Should().HaveCount(2); }
private async Task DeleteEmployeeAsync() { IsProcessing = true; var request = new RemoveInterpreterFromAgencyRequestModel() { AgencyId = _agencyId.ToString(), InterpreterId = _employee.InterpreterId, }; var service = new AgencyService(); var responce = await service.RemoveInterpreterFromAgency(request); IsProcessing = false; var success = responce.Status == true; if (success) { _parentViewModel.RefreshCommand.Execute(null); await App.Current.MainPage.DisplayAlert("Success", responce.GetMessage(), "OK"); await App.Current.MainPage.Navigation.PopAsync(); } else { await App.Current.MainPage.DisplayAlert("Error", responce.GetMessage(), "OK"); } }
public static MvcHtmlString AgencyDropDownListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, object defaultValue, string optionLabel, object htmlAttributes) { AgencyService service = new AgencyService(); var list = service.GetEntities().ToSelectListBy("AgencyID", o => o.AgencyName); return(DropDownListExtensions.DropDownListFor(htmlHelper, expression, defaultValue, list, optionLabel, htmlAttributes)); }
private async Task AddInterpreterToAgencyAsync() { IsProcessing = true; var request = new AddInterpreterToAgencyRequestModel() { AgencyId = _agencyId.ToString(), InterpreterId = lblId.Text, IsManager = SwitchIsManager.IsToggled ? "1" : "0", }; var service = new AgencyService(); var responce = await service.AddInterpreterToAgency(request); IsProcessing = false; var success = responce.Status == true; if (success) { _parentViewModel.RefreshCommand.Execute(null); await App.Current.MainPage.DisplayAlert("Success", responce.GetMessage(), "OK"); } else { await App.Current.MainPage.DisplayAlert("Error", responce.GetMessage(), "OK"); } }
public async Task <List <AgencyResponse> > GetAgenciesAsync(string city) { List <AgencyResponse> agencyResponses = await AgencyService.GetAgencyAsync(); ProcessResponseToDataBase(agencyResponses); return(agencyResponses.Where(a => a.City.Equals(city)).ToList()); }
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"); }
private void EndGetAgencies(IAsyncResult result) { try { Agencies = new ObservableCollection <AgencyViewModel>(AgencyService.EndGetAgencies(result).Select(x => new AgencyViewModel(x))); } catch (SecurityAccessDeniedException ex) { LogService.BeginLogError(ex.Message, null, null); } }
public async Task AddAgencyToDb_When_NoGlobalAgencyRegionLabel_ShouldNotCreateGlobalAgencyAndRegion() { // Arrange var a5Agency = await PrepareTestData(); // Act await AgencyService.AddAgencyToDb(a5Agency); // Assert EFContext.GlobalAgency.Should().HaveCount(0); EFContext.GlobalAgencyRegion.Should().HaveCount(0); }
private async Task GetEmployeeInfoAsync() { IsProcessing = true; var request = new InterpreterInfoRequestModel() { InterpreterId = _employee.InterpreterId }; var service = new AgencyService(); var result = await service.FetchInterpreterInfo(request); IsProcessing = false; }
private async Task <AgencyInterpreter[]> FetchDataAsync(string fromId) { var request = new AgencyInterpretersRequestModel() { AgencyId = AgencyId.ToString(), FromInterpreterId = fromId, }; var service = new AgencyService(); var responce = await service.FetchInterpretersForAgency(request); return(responce.AgencyInterpreters); }
public async Task AddAgencyToDb_When_ValidGlobalAgencyRegionLabel_And_NewGlobalAgency_Should_CreateGlobalAgencyAndRegion() { // Arrange var agencyName = "Saatchi"; var regionName = "Japan"; var globalAgencyRegionLabel = $"{Constants.BusinessUnit.GlobalAgencyRegionLabelPrefix}{agencyName}_{regionName}"; var a5Agency = await PrepareTestData(globalAgencyRegionLabel); // Act await AgencyService.AddAgencyToDb(a5Agency); // Assert EFContext.GlobalAgency.Should().HaveCount(1); EFContext.GlobalAgencyRegion.Should().HaveCount(1); }
public async Task AddAgencyToDb_When_RegionIsMissingInGlobalAgencyRegionLabel_And_NewGlobalAgency_ShouldNotCreateGlobalAgencyAndRegion() { // Arrange var agencyName = "Saatchi"; var regionName = ""; var globalAgencyRegionLabel = $"{Constants.BusinessUnit.GlobalAgencyRegionLabelPrefix}{agencyName}_{regionName}"; var a5Agency = await PrepareTestData(globalAgencyRegionLabel); // Act await AgencyService.AddAgencyToDb(a5Agency); // Assert EFContext.GlobalAgency.Should().HaveCount(0); EFContext.GlobalAgencyRegion.Should().HaveCount(0); LoggerAsMock.Verify(l => l.Error(It.IsAny <string>()), Times.Once); }
public async Task LoadData(String minDay, String maxDay, UserTypes userType) { IsLoading = true; var callLogRequestModel = new CallReportRequestModel(); callLogRequestModel.MinDay = minDay; callLogRequestModel.MaxDay = maxDay; FetchABReportResponse response = null; switch (userType) { case UserTypes.Business: BusinessService businessService = new BusinessService(); if (Business != null) { callLogRequestModel.ClientBusinessId = int.Parse(Business.ClientBusinessId); response = await businessService.FetchBusinessReport(callLogRequestModel); } break; case UserTypes.Agency: AgencyService agencyService = new AgencyService(); if (Agency != null) { callLogRequestModel.AgencyId = int.Parse(Agency.InterpreterBusinessId); response = await agencyService.FetchAgencyReport(callLogRequestModel); } break; } var reportInfo = userType == UserTypes.Agency ? response.AgencyReport : response.BusinessReport; var fee = userType == UserTypes.Agency ? reportInfo.FeeInfos.First().FeePerMinute : reportInfo.BillInfo.First().FeePerMinute; var billOrFeeAmount = userType == UserTypes.Agency ? reportInfo.Report.TotalFee : reportInfo.Report.TotalBill; TotalCallSeconds = reportInfo.Report.TotalCall.ToString(); TotalPausedSeconds = reportInfo.Report.TotalPause.ToString(); BusinessFee = fee.ToString(); TotalBill = billOrFeeAmount.ToString(); IsLoading = false; }
public async Task AddAgencyToDb_When_MultipleGlobalAgencyRegionLabels__Should_UseFirstLabel() { // Arrange var agencyName1 = "Saatchi1"; var regionName1 = "Japan1"; var agencyName2 = "Saatchi2"; var regionName2 = "Japan2"; var globalAgencyRegionLabel1 = $"{Constants.BusinessUnit.GlobalAgencyRegionLabelPrefix}{agencyName1}_{regionName1}"; var globalAgencyRegionLabel2 = $"{Constants.BusinessUnit.GlobalAgencyRegionLabelPrefix}{agencyName2}_{regionName2}"; var a5Agency = await PrepareTestData(globalAgencyRegionLabel1, globalAgencyRegionLabel2); // Act await AgencyService.AddAgencyToDb(a5Agency); // Assert EFContext.GlobalAgency.Should().HaveCount(1); EFContext.GlobalAgencyRegion.Should().HaveCount(1); EFContext.GlobalAgency.First().Name.Should().Be(agencyName1); EFContext.GlobalAgencyRegion.First().Region.Should().Be(regionName1); }
public void Init() { EFContext = EFContextFactory.CreateInMemoryEFContext(); LoggerAsMock = new Mock <ILogger>(); AppSettings = new Mock <IOptions <AppSettings> >(); AppSettings.Setup(a => a.Value).Returns(new AppSettings { AdminUser = "******", CostsAdminUserId = "77681eb0-fc0d-44cf-83a0-36d51851e9ae" }); PermissionServiceMock = new Mock <IPermissionService>(); PgUserServiceMock = new Mock <IPgUserService>(); PluginAgencyServiceMock = new Mock <IPluginAgencyService>(); UserServices = new EditableList <Lazy <IPgUserService, PluginMetadata> > { new Lazy <IPgUserService, PluginMetadata>( () => PgUserServiceMock.Object, new PluginMetadata { BuType = BuType.Pg }) }; PluginAgencyServices = new List <Lazy <IPluginAgencyService, PluginMetadata> > { new Lazy <IPluginAgencyService, PluginMetadata>( () => PluginAgencyServiceMock.Object, new PluginMetadata { BuType = BuType.Pg }) }; AgencyService = new AgencyService( EFContext, LoggerAsMock.Object, PermissionServiceMock.Object, UserServices, PluginAgencyServices, AppSettings.Object); JsonReader = new JsonTestReader(); }
public async Task HandleA5EventObject_BU_AgencyCreated() { //Setup var a5Agency = await GetA5Agency(); var labelz = a5Agency._cm.Common.Labels.ToList(); labelz.Add("CM_Prime_P&G"); a5Agency._cm.Common.Labels = labelz.ToArray(); var costUser = new CostUser { Id = Guid.NewGuid(), GdamUserId = a5Agency.CreatedBy._id, ParentId = Guid.NewGuid() }; var agency = new Agency { Id = Guid.NewGuid(), GdamAgencyId = a5Agency._id }; var brand = new Brand { Id = Guid.NewGuid(), Name = "Brand", AdIdPrefix = "prefix" }; var country = new Country { Iso = "GB", Id = Guid.NewGuid() }; var currency = new Currency { DefaultCurrency = true, Code = "TEST", Description = "Test Currency" }; var costUsers = new List <CostUser> { costUser }.AsQueryable(); var brands = new List <Brand> { brand }.AsQueryable(); var abstractTypes = new List <AbstractType> { new AbstractType { Type = AbstractObjectType.Agency.ToString(), Id = Guid.NewGuid() }, new AbstractType { Type = AbstractObjectType.Module.ToString(), Module = new Module { ClientType = ClientType.Pg }, Id = Guid.NewGuid() } }; EFContext.AbstractType.AddRange(abstractTypes); EFContext.Country.Add(country); EFContext.Agency.Add(new Agency { Name = "Media Agency", Version = 1, Labels = new string[] { } }); EFContext.CostUser.AddRange(costUsers); EFContext.Brand.AddRange(brands); EFContext.Currency.Add(currency); EFContext.SaveChanges(); PluginAgencyServiceMock.Setup(a => a.AddAgencyAbstractType(It.IsAny <Agency>(), It.IsAny <AbstractType>())) .ReturnsAsync(new AbstractType { Id = Guid.NewGuid(), ObjectId = Guid.NewGuid() }); PgUserServiceMock.Setup(a => a.AddUsersToAgencyAbstractType(It.IsAny <AbstractType>(), It.IsAny <Guid>())).Returns(Task.CompletedTask); //Act var addedAgency = await AgencyService.AddAgencyToDb(a5Agency); //Assert PermissionServiceMock.Verify(a => a.CreateDomainNode(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); EFContext.Agency.Should().HaveCount(2); EFContext.AbstractType.Should().HaveCount(3); EFContext.GlobalAgencyRegion.Should().HaveCount(0); EFContext.GlobalAgency.Should().HaveCount(0); addedAgency.Should().NotBeNull(); addedAgency.Name.Should().Be("Saatchi"); addedAgency.Labels.Length.Should().Be(7); addedAgency.GdamAgencyId.Should().Be(a5Agency._id); }
public async Task LoadData(String fromDate, String minDay, String maxDay, UserTypes userType) { IsLoading = true; _minDay = minDay; _maxDay = maxDay; _userType = userType; var fifteenCallsRequestModel = new FifteenCallsRequestModel(); fifteenCallsRequestModel.FromDate = fromDate; fifteenCallsRequestModel.MinDay = minDay; fifteenCallsRequestModel.MaxDay = maxDay; FetchFifteenCallsRespnse response = null; FetchFifteenCallsABResponse ABresponse = null; switch (userType) { case UserTypes.Interpreter: InterpreterService interpreterService = new InterpreterService(); response = await interpreterService.FetchFifteenCalls(fifteenCallsRequestModel); break; case UserTypes.Client: ClientService clientService = new ClientService(); response = await clientService.FetchFifteenCalls(fifteenCallsRequestModel); break; case UserTypes.Business: BusinessService businessService = new BusinessService(); if (Business != null) { fifteenCallsRequestModel.ClientBusinessId = int.Parse(Business.ClientBusinessId); ABresponse = await businessService.FetchFifteenCalls(fifteenCallsRequestModel); } break; case UserTypes.Agency: AgencyService agencyService = new AgencyService(); if (Agency != null) { fifteenCallsRequestModel.AgencyId = int.Parse(Agency.InterpreterBusinessId); ABresponse = await agencyService.FetchFifteenCalls(fifteenCallsRequestModel); } break; } if (response != null) { foreach (var call in response.Calls) { CallLogs.Add(call); } } if (ABresponse != null && ABresponse.Call != null) { foreach (var call in ABresponse.Call.Calls) { CallLogs.Add(call); } } IsLoading = false; }
public static ResponseObject <bool> AcceptRequestFromITSupporter(int itSupporterId, int requestId, bool isAccept) { //MemoryCacher memoryCacher = new MemoryCacher(); RedisTools redisTools = new RedisTools(); try { var requestService = new RequestService(); var itSupporterService = new ITSupporterService(); var requestHistoryService = new RequestHistoryService(); var ticketService = new TicketService(); if (isAccept) { var request = requestService.GetAll().SingleOrDefault(p => p.RequestId == requestId); var itSupporter = itSupporterService.GetAll().SingleOrDefault(p => p.ITSupporterId == itSupporterId); if (request != null && itSupporter != null) { request.RequestStatus = (int)RequestStatusEnum.Processing; request.CurrentITSupporter_Id = itSupporter.ITSupporterId; request.StartTime = DateTime.UtcNow.AddHours(7); requestService.Update(request); itSupporterService.Update(itSupporter); itSupporter.IsBusy = true; var ticketsOfRequest = ticketService.GetAll().Where(p => p.RequestId == requestId).ToList(); foreach (var ticket in ticketsOfRequest) { ticket.UpdateDate = DateTime.UtcNow; ticketService.Update(ticket); } //memoryCacher.Delete("ITSupporterListWithWeights"); redisTools.Clear("ITSupporterListWithWeights"); return(new ResponseObject <bool> { IsError = false, SuccessMessage = "Nhận thành công", ObjReturn = true }); } } else { //var itSupporterFound = memoryCacher.GetValue("ITSupporterListWithWeights"); var itSupporterFound = redisTools.Get("ITSupporterListWithWeights"); Queue <RenderITSupporterListWithWeight> idSupporterListWithWeights; if (itSupporterFound != null) { idSupporterListWithWeights = JsonConvert.DeserializeObject <Queue <RenderITSupporterListWithWeight> >(itSupporterFound); if (idSupporterListWithWeights.Count > 1) { var rejected = idSupporterListWithWeights.Dequeue(); rejected.TimesReject++; var requestHistory = new RequestHistory() { IsITSupportAccept = false, IsDelete = false, Pre_It_SupporterId = rejected.ITSupporterId, RequestId = requestId, CreateDate = DateTime.UtcNow.AddHours(7) }; requestHistoryService.Add(requestHistory); var idSupporterListWithWeightNext = idSupporterListWithWeights.FirstOrDefault(); Console.WriteLine($"REjecct --- {rejected.TimesReject}"); if (rejected.TimesReject < 3) { Console.WriteLine($"Ho tro vien {rejected.ITSupporterName} da tu choi {rejected.TimesReject} lan"); idSupporterListWithWeights.Enqueue(rejected); } else { Console.WriteLine($"Reject ho tro vien {rejected.ITSupporterName}"); var itSupporter = itSupporterService.GetAll().SingleOrDefault(p => p.ITSupporterId == rejected.ITSupporterId); itSupporter.IsOnline = false; itSupporterService.Update(itSupporter); FirebaseService firebaseService = new FirebaseService(); firebaseService.SendNotificationFromFirebaseCloudForITSupporterOffline(rejected.ITSupporterId); Console.WriteLine($"ho tro vien {rejected.ITSupporterName} da offline"); } //memoryCacher.Add("ITSupporterListWithWeights", idSupporterListWithWeights, DateTimeOffset.UtcNow.AddHours(1)); redisTools.Save("ITSupporterListWithWeights", idSupporterListWithWeights); if (idSupporterListWithWeightNext != null) { FirebaseService firebaseService = new FirebaseService(); firebaseService.SendNotificationFromFirebaseCloudForITSupporterReceive(idSupporterListWithWeightNext.ITSupporterId, requestId); int counter = 60; while (counter > 0) { Console.WriteLine($"Gui lai sau khi tu choi trong {counter} giây"); counter--; Thread.Sleep(1000); } AcceptRequestFromITSupporter(idSupporterListWithWeightNext.ITSupporterId, requestId, false); return(new ResponseObject <bool> { IsError = false, WarningMessage = "Nhận duoc thong tin ho tro vien", ObjReturn = true }); } else { //memoryCacher.Delete("ITSupporterListWithWeights"); redisTools.Clear("ITSupporterListWithWeights"); var agencyService = new AgencyService(); var result = FindITSupporterByRequestId(requestId); if (!result.IsError && result.ObjReturn > 0) { FirebaseService firebaseService = new FirebaseService(); firebaseService.SendNotificationFromFirebaseCloudForITSupporterReceive(result.ObjReturn, requestId); int counter = 60; while (counter > 0) { Console.WriteLine($"gui lai yeu cau trong {counter} giay"); counter--; Thread.Sleep(1000); } AcceptRequestFromITSupporter(result.ObjReturn, requestId, false); } } } else { var rejected = idSupporterListWithWeights.Dequeue(); rejected.TimesReject++; var requestHistory = new RequestHistory() { IsITSupportAccept = false, IsDelete = false, Pre_It_SupporterId = rejected.ITSupporterId, RequestId = requestId, CreateDate = DateTime.UtcNow.AddHours(7) }; requestHistoryService.Add(requestHistory); var idSupporterListWithWeightNext = idSupporterListWithWeights.FirstOrDefault(); Console.WriteLine($"REjecct --- {rejected.TimesReject}"); if (rejected.TimesReject < 3) { Console.WriteLine($"Ho tro vien {rejected.ITSupporterName} da tu choi {rejected.TimesReject} lan!"); idSupporterListWithWeights.Enqueue(rejected); } else { Console.WriteLine($"Chuyen trang thai ho tro vien {rejected.ITSupporterName} thanh offline!"); var itSupporter = itSupporterService.GetAll().SingleOrDefault(p => p.ITSupporterId == rejected.ITSupporterId); itSupporter.IsOnline = false; itSupporterService.Update(itSupporter); FirebaseService firebaseService2 = new FirebaseService(); firebaseService2.SendNotificationFromFirebaseCloudForITSupporterOffline(rejected.ITSupporterId); Console.WriteLine($"ho tro vien {rejected.ITSupporterName} da offline"); } //memoryCacher.Add("ITSupporterListWithWeights", idSupporterListWithWeights, DateTimeOffset.UtcNow.AddHours(1)); redisTools.Save("ITSupporterListWithWeights", idSupporterListWithWeights); FirebaseService firebaseService = new FirebaseService(); idSupporterListWithWeightNext = idSupporterListWithWeights.FirstOrDefault(); firebaseService.SendNotificationFromFirebaseCloudForITSupporterReceive(idSupporterListWithWeightNext.ITSupporterId, requestId); int counter = 60; while (counter > 0) { Console.WriteLine($"Gui lại sau khi tu choi trong {counter} giây"); counter--; Thread.Sleep(1000); } AcceptRequestFromITSupporter(idSupporterListWithWeightNext.ITSupporterId, requestId, false); } } } return(new ResponseObject <bool> { IsError = true, WarningMessage = "Nhận thất bại", ObjReturn = false }); } catch (Exception e) { return(new ResponseObject <bool> { IsError = true, WarningMessage = "Nhận thất bại", ObjReturn = false, ErrorMessage = e.ToString() }); } }
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() }); } }
public async Task HandleA5EventObject_Media_AgencyCreated() { //Setup var basePath = AppContext.BaseDirectory; var filePath = $"{basePath}{Path.DirectorySeparatorChar}JsonData{Path.DirectorySeparatorChar}a5_agency.json"; var a5Agency = await JsonReader.GetObject <A5Agency>(filePath, true); a5Agency._cm.Common.Labels = a5Agency._cm.Common.Labels.Where(a => !a.StartsWith("SMO_")).ToArray(); PermissionServiceMock.Setup(a => a.CreateDomainNode(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>())) .ReturnsAsync(new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }); var costUser = new CostUser { Id = Guid.NewGuid(), GdamUserId = a5Agency.CreatedBy._id, ParentId = Guid.NewGuid() }; var agency = new Agency { Id = Guid.NewGuid(), GdamAgencyId = a5Agency._id }; var brand = new Brand { Id = Guid.NewGuid(), Name = "Brand", AdIdPrefix = "prefix" }; var country = new Country { Iso = "GB", Id = Guid.NewGuid() }; var currency = new Currency { DefaultCurrency = true, Code = "TEST", Description = "Test Currency" }; var costUsers = new List <CostUser> { costUser }.AsQueryable(); var brands = new List <Brand> { brand }.AsQueryable(); var abstractTypes = new List <AbstractType> { new AbstractType { Type = AbstractObjectType.Agency.ToString(), Id = Guid.NewGuid() }, new AbstractType { Type = AbstractObjectType.Module.ToString(), Module = new Module { ClientType = ClientType.Pg }, Id = Guid.NewGuid() } }; EFContext.AbstractType.AddRange(abstractTypes); EFContext.Country.Add(country); EFContext.CostUser.AddRange(costUsers); EFContext.Brand.AddRange(brands); EFContext.Currency.Add(currency); EFContext.SaveChanges(); //Act await AgencyService.AddAgencyToDb(a5Agency); //Assert PermissionServiceMock.Verify(a => a.CreateDomainNode(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); EFContext.Agency.Should().HaveCount(1); EFContext.GlobalAgencyRegion.Should().HaveCount(0); EFContext.GlobalAgency.Should().HaveCount(0); }
private void LoadAgencies() { AgencyService.BeginGetAgencies(EndGetAgencies, null); }
public AgencyController(AgencyService agencyServ) { this.agencyServ = agencyServ; }
public void LoadData() { ProfileService.BeginGetCustomerProfiles(EndGetCustomersProfile, null); TagService.BeginGetStandardTags(EndGetStandardTags, null); AgencyService.BeginGetAgencies(EndGetAgencies, null); }
private async Task <string> DetermineNewOrgCode(CommitAgencyRequest commitAgencyRequest, AgencyService agencyService) { if (commitAgencyRequest.Organization.OrganizationType != OrganizationType.ThirdParty) { return(commitAgencyRequest.Organization.OrganizationCode.Trim()); } var str = commitAgencyRequest.Organization.OrganizationName.Trim().ToUpper().Replace(" ", ""); var str2 = string.Empty; if (str.Length >= 7) { str2 = str.Substring(0, 7); } else { str2 = str; for (var i = str.Length; i < 7; i++) { str2 += "0"; } } var suffixNumber = 1; var str3 = string.Empty; var keepTrying = true; while (keepTrying && suffixNumber <= 100) { try { str3 = str2 + suffixNumber.ToString(); var result = await agencyService.GetAgency(new GetOrganizationRequestData { OrganizationCode = str3 }); if (result == null || result.Organization == null) { keepTrying = false; } } catch {} finally { suffixNumber++; } } if (keepTrying) { throw new ResponseErrorException(ResponseErrorCode.OrganizationCodeGenerationFailure, "Failed to generate Organization Code for third party organization. "); } return(str3); }
public AgencyController(UserContext context) { this._context = context; this.agencyService = new AgencyService(context); }