public IHttpActionResult GetAllServiceRepositories( [FromBody] BaseReportFilter <ReportFilter> filter) { var res = new ApiPagedCollectionResponse <ServiceRepositoryDto> { Result = new List <ServiceRepositoryDto>() }; try { var repo = AuthorizeProvider.GetAllServiceRepositories(filter); repo = SetKendoFilter(filter, repo); res = new ApiPagedCollectionResponse <ServiceRepositoryDto> { Result = repo, Message = ((int)RuleExceptionCodeCommon.ValidResult).ToString(), TotalRecords = repo.Count }; } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); res.Message = BusinessRuleHelper.GetExceptionCode(ex).ToString(); } return(Json(res)); }
/// <summary> /// AMSTS-17 2017-5-7 /// </summary> /// <param name="filter"></param> /// <returns></returns> public List <Domain.DTO.UserManagement> GetUsersByFilter(BaseReportFilter <Domain.DTO.UserManagement> filter) { try { //var model = AuthenticationManager.AuthenticationProvider.GetApplicationUsers(); //var result = model.Select(x => new Domain.DTO.UserManagement //{ // UserName = x.UserName, // DisplayName = x.DisplayName, // Email = x.Email, // CreateDate = x.CreateDate.ConvertMiladiToJalali(), // PhoneNumber = x.PhoneNumber, // Status = (UserStatus)x.Status, // RoleId = x.RoleId //}); var result = UserManagementService.GetUserManagements(); return(result.ToList()); } catch (Exception ex) { throw ex; } }
public async Task ComplexDataSendCaptureBody() { var sutEnv = StartSutEnv(new MockConfigSnapshot(new NoopLogger(), captureBody: ConfigConsts.SupportedValues.CaptureBodyAll)); // build test data, which we send to the sample app var data = new BaseReportFilter <SendMessageFilter> { ReportFilter = new SendMessageFilter { Body = "message body", SenderApplicationCode = "26", MediaType = "TokenBasedSms", Recipients = new List <string> { "abc123" } } }; var body = JsonConvert.SerializeObject(data, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); // send data to the sample app var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); // make sure the sample app received the data result.StatusCode.Should().Be(200); // and make sure the data is captured by the agent sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); sutEnv.MockPayloadSender.FirstTransaction.Context.Request.Body.Should().Be(body); }
public async Task ComplexDataSendCaptureBody() { // build test data, which we send to the sample app var data = new BaseReportFilter <SendMessageFilter>(); data.ReportFilter = new SendMessageFilter(); data.ReportFilter.Body = "message body"; data.ReportFilter.SenderApplicationCode = "26"; data.ReportFilter.MediaType = "TokenBasedSms"; data.ReportFilter.Recipients = new List <string> { "abc123" }; var body = JsonConvert.SerializeObject(data, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); // send data to the sample app var httpClient = new HttpClient(); httpClient.BaseAddress = new Uri("http://localhost:5903"); var result = await httpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); // make sure the sample app received the data result.StatusCode.Should().Be(200); // and make sure the data is captured by the agent _payloadSender1.FirstTransaction.Should().NotBeNull(); _payloadSender1.FirstTransaction.Context.Request.Body.Should().Be(body); }
//public BaseReportProvider ReportProvider = new BaseReportProvider(); //public PartyProvider PartyProvider => Core.Container.Resolve<PartyProvider>(); ///// <summary> ///// ///// </summary> ///// <param name="filter"></param> ///// <param name="result"></param> ///// <typeparam name="T"></typeparam> ///// <typeparam name="TK"></typeparam> ///// <returns></returns> protected List <TK> SetKendoFilter <T, TK>(BaseReportFilter <T> filter, List <TK> result) { try { if (filter?.OptionalFilter != null && filter?.OptionalFilter.skip >= 0 && filter?.OptionalFilter.take > 0) { result = result.Skip(filter.OptionalFilter.skip).Take(filter.OptionalFilter.take).ToList(); } if (filter?.OptionalFilter?.sort != null && filter?.OptionalFilter.sort.Count > 0) { result = filter.OptionalFilter.sort[0].dir == "desc" ? result.OrderByDescending( x => x.GetType().GetProperty(filter.OptionalFilter.sort[0].field).GetValue(x, null)) .ToList() : result.OrderBy( x => x.GetType().GetProperty(filter.OptionalFilter.sort[0].field).GetValue(x, null)) .ToList(); } return(result); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw; } }
public IHttpActionResult GetAllPageAccessBasedOnRoles( [FromBody] BaseReportFilter <ReportFilter> filter) { var res = new ApiPagedCollectionResponse <FlatServiceAccess> { }; try { var data = AuthorizeProvider.GetAllPageAccessBasedOnRoles(Applications.IranMarketerFund); res = new ApiPagedCollectionResponse <FlatServiceAccess> { Message = (RuleExceptionCodeCommon.ValidResult).GetEnumDescription(), BRuleCode = (int)RuleExceptionCodeCommon.ValidResult, Result = data, TotalRecords = data.Count }; } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); res.Message = BusinessRuleHelper.GetException(ex); res.BRuleCode = BusinessRuleHelper.GetExceptionCode(ex); } return(Json(res)); }
public async Task ApmMiddleware_ShouldSkipCapturing_WhenInvalidContentType() { // Arrange var sutEnv = StartSutEnv(new MockConfiguration(new NoopLogger(), captureBody: ConfigConsts.SupportedValues.CaptureBodyErrors)); // build test data, which we send to the sample app var data = new BaseReportFilter <SendMessageFilter> { ReportFilter = new SendMessageFilter { Body = "message body", SenderApplicationCode = "26", MediaType = "TokenBasedSms", Recipients = new List <string> { "abc123" } } }; var body = JsonConvert.SerializeObject(data, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); var content = new StringContent(body, Encoding.UTF8); content.Headers.Clear(); content.Headers.TryAddWithoutValidation("Content-Type", "123"); // Act var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", content); // Assert result.StatusCode.Should().Be(HttpStatusCode.UnsupportedMediaType); }
public void AddServiceRepository(BaseReportFilter <ServiceRepositoryDto> model) { try { BRule.Assert( model.ReportFilter.Code != null && model.ReportFilter.MethodName != null && model.ReportFilter.ServiceName != null && model.ReportFilter.Title != null, RuleExceptionCodeCommon.AllParametersAreRequired.GetEnumDescription(), (int)RuleExceptionCodeCommon.AllParametersAreRequired); var repo = ServiceRepositoryService.GetServiceRepositories(); var entity = new ServiceRepository { Code = model.ReportFilter.Code, MethodName = model.ReportFilter.MethodName, ServiceName = model.ReportFilter.ServiceName, Title = model.ReportFilter.Title }; ServiceRepositoryService.Save(entity); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw; } }
public PageCollection <Customer> GetFlatCustomers(BaseReportFilter <FlatCustomerReportFilter> filter) { try { return(Dao.GetFlatCustomers(filter)); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw ex; } }
/// <summary> /// </summary> /// <param name="filter"></param> /// <returns></returns> public Domain.DTO.UserManagement GetUserInformationByUserName(BaseReportFilter <UserManagementEditFilter> filter) { try { var username = filter.ReportFilter?.UserName; BRule.Assert(!username.IsNullOrEmpty(), RuleExceptionCodeUserManagement.UserNameIsEmpty.GetEnumDescription(), (int)RuleExceptionCodeUserManagement.UserNameIsEmpty); var key = string.Format(pattern, username); var dtoCache = CustomCache.Get(key) as Domain.DTO.UserManagement; if (dtoCache != null) { return(dtoCache); } //var user = AuthenticationManager.AuthenticationProvider.UserManager.FindByName(username); //TODO //Mapper.CreateMap<IdentityModels.ApplicationUser, Domain.DTO.UserManagement>().ForMember(dest => dest.CreateDate, // opt => opt.MapFrom(src => src.CreateDate.ConvertMiladiToJalali())); //var model = Mapper.Map<IdentityModels.ApplicationUser, Domain.DTO.UserManagement>(user); var model = UserManagementService.GetUserByUserName(username); var party = PartyProvider.GetByUserName(username); if (party != null) { var branch = PartyBranchService.GetAll().FirstOrDefault(x => x.PartyId == party.Id && x.ValidUntil == null); if (branch?.BranchId != null) { if (branch?.BranchId != null) { model.BranchId = (int)branch?.BranchId; } } } model.RolesCodeList = AuthenticationManager.AuthenticationProvider.UserManager.GetRoles(model.Id).ToList(); CustomCache.Insert(key, model, 1200); return(model); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw; } }
public void AddServiceAccessByRoleIdAndPage(BaseReportFilter <ServiceAccessAddFilter> filter) { try { BRule.Assert(filter?.ReportFilter?.ApplicationRole != null, RuleExceptionCodeCommon.AllParametersAreRequired.GetEnumDescription(), (int)RuleExceptionCodeCommon.AllParametersAreRequired); ServiceAccessService.AddServiceAccessByRoleIdAndPage(filter.ReportFilter.ApplicationRole.Id, filter.ReportFilter.PageTypes, Applications.IranMarketerFund); } catch (Exception e) { Logger.ErrorException(e.Message, e); throw; } }
//public List<ServiceAccessDto> GetAllServiceAccessByUserName(BaseReportFilter<ReportFilter> filter) //{ // try // { // var service = AccessService.GetServiceAccesses().Where(x => x.UserId != null && x.Allow = true); // foreach (var serviceAccess in service) // { // } // var result = service.Select(t => // { // var serviceRep = // RepositoryService.GetServiceRepositories() // .FirstOrDefault(x => x.Id == t.ServiceRepositoryId); // return new ServiceAccessDto // { // Allow = t.Allow, // Id = t.Id, // UserName = // !t.UserId.IsNullOrEmpty() // ? AuthenticationManager.AuthenticationProvider.UserManager.FindByIdAsync(t.UserId) // .Result.UserName // : null, // LastUpdate = t.LastUpdate.ConvertMiladiToJalali(), // RoleName = // AuthenticationManager.AuthenticationProvider.RoleManager.FindByIdAsync(t.RoleId) // .Result?.Name, // ControllerName = serviceRep?.ServiceName, // MethodNameEn = serviceRep?.MethodName, // MethodNameFa = serviceRep?.Title, // Code = serviceRep?.Code, // ApplicationTitle = ((Applications)t.ApplicationId).ToString() // }; // } // ); // return result.ToList(); // } // catch (Exception ex) // { // Logger.ErrorException(ex.Message, ex); // throw; // } //} //public void UpdateAccess(BaseReportFilter<ServiceAccessUpdateFilter> model) //{ // try // { // foreach (var access in model.ReportFilter.AccessDtos) // { // BRule.Assert(access.Allow != null && access.Id > 0, // RuleExceptionCode.AllParametersAreRequired.GetEnumDescription(), // (int)RuleExceptionCode.AllParametersAreRequired); // AccessService.UpdateAccess(new ServiceAccess // { // Id = access.Id, // Allow = access.Allow, // LastUpdate = DateTime.Now // }); // } // } // catch (Exception ex) // { // Logger.ErrorException(ex.Message, ex); // throw ex; // } //} public void AddServiceAccessByUserNameAndPage(BaseReportFilter <ServiceAccessAddFilter> filter) { try { BRule.Assert((bool)!filter?.ReportFilter?.UserNames?.FirstOrDefault().IsNullOrEmpty(), RuleExceptionCodeCommon.AllParametersAreRequired.GetEnumDescription(), (int)RuleExceptionCodeCommon.AllParametersAreRequired); ServiceAccessService.AddServiceAccessByUserNameAndPage(filter.ReportFilter.UserNames.FirstOrDefault(), null, Applications.IranMarketerFund); } catch (Exception e) { Logger.ErrorException(e.Message, e); throw; } }
public PageCollection <Customer> GetFlatCustomers(BaseReportFilter <FlatCustomerReportFilter> filter) { try { try { var command = new CustomCommand { CommandType = CommandType.StoredProcedure, Parameters = new DynamicParameters() }; command.Parameters.Add("PartyId", filter.ReportFilter.PartyId); command.Parameters.Add("BranchId", filter.ReportFilter.BranchId); command.Parameters.Add("NamePhrase", filter.ReportFilter.NamePhrase); command.Parameters.Add("RegionId", filter.ReportFilter.RegionId); command.Parameters.Add("PartyType", filter.ReportFilter.PartyType); command.Parameters.Add("FromDate", filter.ReportFilter.DateFilter.StartDate.Date); command.Parameters.Add("ToDate", filter.ReportFilter.DateFilter.EndDate.Date); command.Parameters.Add("pageSize", filter.OptionalFilter.take); command.Parameters.Add("skip", filter.OptionalFilter.page - 1); var orderClause = ""; if (filter.OptionalFilter?.sort != null) { orderClause = filter.OptionalFilter.sort.Aggregate(orderClause, (current, sort) => current + sort.field + " " + sort.dir + " "); } command.Parameters.Add("orderClause", orderClause); command.SqlCommand = "pm.GetFlatCustomers"; return(GetPageCollection(command, new FlatCustomerRowMapper())); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw ex; } } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw ex; } }
public List <ServiceRepositoryDto> GetAllServiceRepositories(BaseReportFilter <ReportFilter> filter) { try { var repo = ServiceRepositoryService.GetServiceRepositories(); var model = repo.Select(x => new ServiceRepositoryDto { Code = x.Code, MethodName = x.MethodName, ServiceName = x.ServiceName, Title = x.Title }).ToList(); return(model); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw ex; } }
public void AddRoles(BaseReportFilter <AddRoleFilter> model) { try { BRule.Assert(model.ReportFilter.RoleName != null, RuleExceptionCodeUserManagement.InvalidUserName.GetEnumDescription(), (int)RuleExceptionCodeUserManagement.InvalidUserName); if (AuthenticationManager.AuthenticationProvider.RoleManager.FindByName(model.ReportFilter.RoleName) == null) { AuthenticationManager.AuthenticationProvider.CreateRole(model.ReportFilter.RoleName); } } catch (Exception e) { Logger.ErrorException(e.Message, e); throw; } }
public IHttpActionResult AddServiceRepository( [FromBody] BaseReportFilter <ServiceRepositoryDto> filter) { var res = new ApiPagedCollectionResponse <ServiceRepositoryDto> { }; try { AuthorizeProvider.AddServiceRepository(filter); res = new ApiPagedCollectionResponse <ServiceRepositoryDto> { Message = ((int)RuleExceptionCodeCommon.ValidResult).ToString(), }; } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); res.Message = BusinessRuleHelper.GetExceptionCode(ex).ToString(); } return(Json(res)); }
public void UpdateUserInformation(BaseReportFilter <UserManagementUpdateFilter> filter) { try { BRule.Assert(filter?.ReportFilter != null, RuleExceptionCodeCommon.FilterIsNull.GetEnumDescription(), (int)RuleExceptionCodeCommon.FilterIsNull); BRule.Assert(filter.ReportFilter.UserName != null, RuleExceptionCodeUserManagement.InvalidUserName.GetEnumDescription(), (int)RuleExceptionCodeUserManagement.InvalidUserName); BRule.Assert(filter.ReportFilter.DisplayName != null, RuleExceptionCodeUserManagement.DisplayNameIsNull.GetEnumDescription(), (int)RuleExceptionCodeUserManagement.DisplayNameIsNull); var user = AuthenticationManager.AuthenticationProvider.UserManager.FindByName(filter.ReportFilter.UserName); BRule.Assert(user != null, RuleExceptionCodeUserManagement.UserNotFound.GetEnumDescription(), (int)RuleExceptionCodeUserManagement.UserNotFound); var ifExistEmail = AuthenticationManager.AuthenticationProvider.UserManager.FindByEmail(filter.ReportFilter.Email); BRule.Assert(ifExistEmail == null || ifExistEmail.UserName == user.UserName, RuleExceptionCodeUserManagement.EmailExits.GetEnumDescription(), (int)RuleExceptionCodeUserManagement.EmailExits); BRule.Assert(!filter.ReportFilter.PhoneNumber.IsNullOrEmpty(), RuleExceptionCodeUserManagement.InvalidMoileNumber.GetEnumDescription(), (int)RuleExceptionCodeUserManagement.InvalidMoileNumber); Mapper.CreateMap <UserManagementUpdateFilter, IdentityModels.ApplicationUser>() .ForMember(dest => dest.CreateDate, opt => opt.MapFrom(src => DateTime.Now)) .ForMember(dest => dest.Status, opt => opt.MapFrom(src => (int)src.Status)) .ForMember(dest => dest.Id, opt => opt.Ignore()) .ForMember(dest => dest.UserName, opt => opt.Ignore()) .ForMember(dest => dest.PasswordHash, opt => opt.Ignore()); var result = Mapper.Map(filter.ReportFilter, user); AuthenticationManager.AuthenticationProvider.UserManager.Update(result); var currentRole = AuthenticationManager.AuthenticationProvider.UserManager.GetRoles(user.Id); if (currentRole != null) { AuthenticationManager.AuthenticationProvider.UserManager.RemoveFromRoles(user.Id, currentRole.ToArray()); if (filter.ReportFilter.RolesCodeList != null) { AuthenticationManager.AuthenticationProvider.UserManager.AddToRoles(user.Id, filter.ReportFilter.RolesCodeList.ToArray()); } } else { if (filter.ReportFilter.RolesCodeList != null) { AuthenticationManager.AuthenticationProvider.UserManager.AddToRoles(user.Id, filter.ReportFilter.RolesCodeList.ToArray()); } } var party = PartyProvider.GetByUserName(filter.ReportFilter.UserName); var partyBranch = PartyBranchService.GetAll().FirstOrDefault(x => x.PartyId == party.Id && x.ValidUntil == null); //TODO update branch //PartyProvider.GetByNationalId() var dbFactory = CoreContainer.Container.Resolve <IDbFactory>(); using (var uow = dbFactory.Create <IUnitOfWork, ISession>(IsolationLevel.Serializable)) { try { partyBranch.ValidUntil = DateTime.Now; partyBranch.ModifiedBy = filter.AuthenticatedUserName; PartyBranchService.SaveOrUpdate(partyBranch, uow); } catch (Exception ex) { uow.Rollback(); throw; } } } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw; } }