/// <summary> /// </summary> /// <param name="server"> /// </param> /// <param name="messageSerializer"> /// </param> /// <param name="bus"> /// </param> public ZoneClient(ZoneServer server, IMessageSerializer messageSerializer, IBus bus) : base(server) { this.server = server; this.messageSerializer = messageSerializer; this.bus = bus; this.dispatcherThread = new Thread(this.DispatchMessages); this.dispatcherThread.Start(); }
public ClientModule(IBus bus, IClientRepository clientRepository, IRepository<User> userRepository) { if (_defaultJsonMaxLength == 0) _defaultJsonMaxLength = JsonSettings.MaxJsonLength; //Hackeroonie - Required, due to complex model structures (Nancy default restriction length [102400]) JsonSettings.MaxJsonLength = Int32.MaxValue; Get["/Clients"] = _ => { var search = Context.Request.Query["search"]; var offset = Context.Request.Query["offset"]; var limit = Context.Request.Query["limit"]; if (offset == null) offset = 0; if (limit == null) limit = 10; var model = this.Bind<DataTablesViewModel>(); var dto = Mapper.Map<IEnumerable<Client>, IEnumerable<ClientDto>>(clientRepository);//.Search(Context.Request.Query["search[value]"].Value, model.Start, model.Length)); return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), new { data = dto.Where(x => x.IsActive != false).ToList() }); }; Get["/ClientLookup"] = parameters => { var filter = ""; if (Context.Request.Query["q_word[]"].HasValue) filter = (string)Context.Request.Query["q_word[]"].Value.ToString(); var pageIndex = 0; var pageSize = 0; int.TryParse(Context.Request.Query["page_num"].Value, out pageIndex); int.TryParse(Context.Request.Query["per_page"].Value, out pageSize); Expression<Func<Client, bool>> predicate = x => x.IsActive && x.Name.StartsWith(filter); var clients = new PagedList<Client>(clientRepository, pageIndex != 0 ? pageIndex - 1 : pageIndex, pageSize == 0 ? 10 : pageSize, predicate); return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), new { result = Mapper.Map<IEnumerable<Client>, IEnumerable<ClientDto>>(clients), cnt_whole = clients.RecordsFiltered }); }; Get["/ClientUsers/{clientId:guid}"] = _ => { var filter = ""; if (Context.Request.Query["q_word[]"].HasValue) filter = (string)Context.Request.Query["q_word[]"].Value.ToString(); var pageIndex = 0; var pageSize = 0; int.TryParse(Context.Request.Query["page_num"].Value, out pageIndex); int.TryParse(Context.Request.Query["per_page"].Value, out pageSize); var clientId = (Guid)_.clientId; var clientUsers = clientRepository.Where(x => x.Id == clientId).SelectMany(x => x.Customers.SelectMany(c => c.CustomerUsers)).Select(x => x.User); Expression<Func<User, bool>> predicate = x => x.IsActive == true && x.UserType == UserType.Internal && (x.Individual.Name.StartsWith(filter) || x.Individual.Surname.StartsWith(filter)); var users = new PagedList<User>(clientUsers, pageIndex != 0 ? pageIndex - 1 : pageIndex, pageSize == 0 ? 10 : pageSize, predicate); return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), new { result = Mapper.Map<IEnumerable<User>, IEnumerable<UserDto>>(users), cnt_whole = users.RecordsFiltered }); }; Get["/ClientLookup/{industryIds?}/{filter:alpha}"] = parameters => { var dto = Enumerable.Empty<NamedEntityDto>(); if (parameters.industryIds.Value != null) { var industryString = (string)parameters.industryIds.Value; var industryIds = industryString.Split(',').Select(x => new Guid(x)).ToArray(); var filter = (string)parameters.filter + ""; var valueEntities = clientRepository.Where(x => (x.Name + "").Trim().ToLower().StartsWith(filter.Trim().ToLower()) && x.Industries.Any(ind => industryIds.Contains(ind.IndustryId))); dto = Mapper.Map<IEnumerable<NamedEntity>, IEnumerable<NamedEntityDto>>(valueEntities); } return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), new { dto }); }; Get["/Clients/Add"] = parameters => View["Save", new ClientDto()]; Post["/Clients"] = _ => { var dto = this.BindAndValidate<ClientDto>(); dto.CreatedBy = Context.CurrentUser.UserName; dto.IsActive = true; if (dto.TrialExpiration == null) dto.TrialExpiration = DateTime.UtcNow.Date; if (ModelValidationResult.IsValid) { var user = userRepository.Get(dto.accountownerlastname_primary_key); var entity = Mapper.Map(dto, clientRepository.Get(dto.Id) ?? new Client()); entity.SetAccountOwner(user); bus.Publish(new CreateUpdateEntity(entity, "Create")); return View["Index"]; } return View["Save", dto]; }; Get["/Clients/{id}"] = parameters => { var guid = (Guid)parameters.id; var client = clientRepository.Get(guid); var dto = Mapper.Map<Client, ClientDto>(client); return View["Save", dto]; }; Get["/Clients/Details/{id}"] = parameters => { var guid = (Guid)parameters.id; var client = clientRepository.Get(guid); var dto = Mapper.Map<Client, ClientDto>(client); return Response.AsJson(dto); }; Put["/Clients/{id}"] = parameters => { var dto = this.BindAndValidate<ClientDto>(); dto.ModifiedBy = Context.CurrentUser.UserName; if (dto.TrialExpiration == null) dto.TrialExpiration = DateTime.UtcNow.Date; if (ModelValidationResult.IsValid) { var user = userRepository.Get(dto.accountownerlastname_primary_key); var entity = Mapper.Map(dto, clientRepository.Get(dto.Id)); entity.SetAccountOwner(user); bus.Publish(new CreateUpdateEntity(entity, "Update")); return View["Index"]; } return View["Save", dto]; }; Put["/Clients/Lock/{id}"] = parameters => { var dto = this.Bind<ClientDto>(); var entity = clientRepository.Get(dto.Id); entity.Modified = DateTime.UtcNow; entity.ModifiedBy = Context.CurrentUser.UserName; entity.Lock(true); bus.Publish(new CreateUpdateEntity(entity, "Update")); return Response.AsJson("Client has been locked"); }; Put["/Clients/UnLock/{id}"] = parameters => { var dto = this.Bind<ClientDto>(); var entity = clientRepository.Get(dto.Id); entity.Modified = DateTime.UtcNow; entity.ModifiedBy = Context.CurrentUser.UserName; entity.Lock(false); bus.Publish(new CreateUpdateEntity(entity, "Update")); return Response.AsJson("Client has been un-locked"); }; Delete["/Clients/{id}"] = _ => { this.RequiresAnyClaim(new[] { RoleType.Admin.ToString(), RoleType.ProductManager.ToString(), RoleType.Support.ToString() }); var dto = this.Bind<ClientDto>(); var entity = clientRepository.Get(dto.Id); bus.Publish(new SoftDeleteEntity(entity)); return Response.AsJson("Client has been soft deleted"); }; }
/// <summary> /// </summary> /// <param name="server"> /// </param> /// <param name="messageSerializer"> /// </param> /// <param name="bus"> /// </param> public ZoneClient(ZoneServer server, IMessageSerializer messageSerializer, IBus bus) : base(server) { this.server = server; this.messageSerializer = messageSerializer; this.bus = bus; this.dispatcherThread = new Thread(this.DispatchMessages); this.dispatcherThread.Start(); }
public CustomerModule(IBus bus, IAdvancedBus eBus, ICustomerRepository customers, IRepository<User> userRepository) { if (_defaultJsonMaxLength == 0) _defaultJsonMaxLength = JsonSettings.MaxJsonLength; //Hackeroonie - Required, due to complex model structures (Nancy default restriction length [102400]) JsonSettings.MaxJsonLength = Int32.MaxValue; Get["/Customers"] = _ => { var search = Context.Request.Query["search"]; var offset = Context.Request.Query["offset"]; var limit = Context.Request.Query["limit"]; if (offset == null) offset = 0; if (limit == null) limit = 10; var model = this.Bind<DataTablesViewModel>(); var dto = Mapper.Map<IEnumerable<Customer>, IEnumerable<CustomerDto>>(customers.Where(x => x.IsActive));//.Search(Context.Request.Query["search[value]"].Value, model.Start, model.Length)); return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), new { data = dto.ToList() }); }; Get["/CustomerLookup/{industryIds?}/{filter:alpha}"] = parameters => { var dto = Enumerable.Empty<NamedEntityDto>(); if (parameters.industryIds.Value != null) { var industryString = (string)parameters.industryIds.Value; var industryIds = industryString.Split(',').Select(x => new Guid(x)).ToArray(); var filter = (string)parameters.filter + ""; var valueEntities = customers.Where(x => (x.Name + "").Trim().ToLower().StartsWith(filter.Trim().ToLower()) && x.Industries.Any(ind => industryIds.Contains(ind.IndustryId))); dto = Mapper.Map<IEnumerable<NamedEntity>, IEnumerable<NamedEntityDto>>(valueEntities); } return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), new { dto }); }; Get["/Customers/Add"] = parameters => { return View["Save", new CustomerDto()]; }; Post["/Customers"] = _ => { var dto = this.BindAndValidate<CustomerDto>(); dto.CreatedBy = Context.CurrentUser.UserName; dto.IsActive = true; if(dto.TrialExpiration == null) dto.TrialExpiration = DateTime.UtcNow.Date; if (ModelValidationResult.IsValid) { var user = userRepository.Get(dto.accountownerlastname_primary_key); var entity = Mapper.Map(dto, new Customer(dto.Name)); entity.SetCreateSource(CreateSourceType.UserManagement); entity.SetAccountOwner(user); bus.Publish(new CreateUpdateEntity(entity, "Create")); return View["Index"]; } return View["Save", dto]; }; Get["/Customers/{id}"] = parameters => { var guid = (Guid)parameters.id; var dto = Mapper.Map<Customer, CustomerDto>(customers.Get(guid)); return View["Save", dto]; }; Get["/Customers/Details/{id}"] = parameters => { var guid = (Guid)parameters.id; var dto = Mapper.Map<Customer, CustomerDto>(customers.Get(guid)); return Response.AsJson(dto); }; Put["/Customers/{id}"] = parameters => { var dto = this.BindAndValidate<CustomerDto>(); dto.ModifiedBy = Context.CurrentUser.UserName; if (dto.TrialExpiration == null) dto.TrialExpiration = DateTime.UtcNow.Date; if (ModelValidationResult.IsValid) { var user = userRepository.Get(dto.accountownerlastname_primary_key); var entity = Mapper.Map(dto, customers.Get(dto.Id)); entity.SetAccountOwner(user); bus.Publish(new CreateUpdateEntity(entity, "Update")); return View["Index"]; } return View["Save", dto]; }; Put["/Customers/Lock/{id}"] = parameters => { var dto = this.Bind<CustomerDto>(); var entity = customers.Get(dto.Id); entity.Modified = DateTime.UtcNow; entity.ModifiedBy = Context.CurrentUser.UserName; entity.Lock(true); bus.Publish(new CreateUpdateEntity(entity, "Update")); return Response.AsJson("Customer has been locked"); }; Put["/Customers/UnLock/{id}"] = parameters => { var dto = this.Bind<CustomerDto>(); var entity = customers.Get(dto.Id); entity.Modified = DateTime.UtcNow; entity.ModifiedBy = Context.CurrentUser.UserName; entity.Lock(false); bus.Publish(new CreateUpdateEntity(entity, "Update")); return Response.AsJson("Customer has been un-locked"); }; Delete["/Customers/{id}"] = _ => { this.RequiresAnyClaim(new[] { RoleType.Admin.ToString(), RoleType.ProductManager.ToString(), RoleType.Support.ToString() }); var dto = this.Bind<CustomerDto>(); var entity = customers.Get(dto.Id); bus.Publish(new SoftDeleteEntity(entity)); return Response.AsJson("Customer has been soft deleted"); }; }
public MemBusAdapter(MemBus.IBus bus) { this.bus = bus; }
public UserModule(IBus bus, IAdvancedBus eBus, IUserRepository userRepository) { if (_defaultJsonMaxLength == 0) _defaultJsonMaxLength = JsonSettings.MaxJsonLength; //Hackeroonie - Required, due to complex model structures (Nancy default restriction length [102400]) JsonSettings.MaxJsonLength = Int32.MaxValue; Get["/Users/All"] = _ => Response.AsJson(Mapper.Map<IEnumerable<User>, IEnumerable<UserDto>>(userRepository)); Get["/Users"] = _ => { var search = Context.Request.Query["search"]; var offset = Context.Request.Query["offset"]; var limit = Context.Request.Query["limit"]; if (offset == null) offset = 0; if (limit == null) limit = 10; var model = this.Bind<DataTablesViewModel>(); var dto = Mapper.Map<IEnumerable<User>, IEnumerable<UserDto>>(userRepository.Where(x => x.IsActive != false));//.Search(Context.Request.Query["search[value]"].Value, model.Start, model.Length)); return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), new { data = dto.ToList() }); }; Get["/UserLookup/{filter}"] = _ => { var filter = (string)_.filter; var dto = Mapper.Map<IEnumerable<User>, IEnumerable<UserDto>>(userRepository.Where(x => x.IsActive == true && (x.Individual.Name.StartsWith(filter) || x.Individual.Surname.StartsWith(filter)))); return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), new { dto }); }; Get["/UserCustomers/{userId:guid}"] = _ => { var userId = (Guid)_.userId; var customers = userRepository.Where(x => x.Id == userId && x.IsActive == true).SelectMany(x => x.CustomerUsers.Select(cu => cu.Customer)); return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), Mapper.Map<IEnumerable<Customer>, IEnumerable<CustomerDto>>(customers)); }; Get["/Userlist"] = parameters => { var filter = ""; if (Context.Request.Query["q_word[]"].HasValue) filter = (string)Context.Request.Query["q_word[]"].Value.ToString(); var pageIndex = 0; var pageSize = 0; int.TryParse(Context.Request.Query["page_num"].Value, out pageIndex); int.TryParse(Context.Request.Query["per_page"].Value, out pageSize); Expression<Func<User, bool>> predicate = x => x.IsActive == true && x.UserType == UserType.Internal && (x.Individual.Name.StartsWith(filter) || x.Individual.Surname.StartsWith(filter)); var users = new PagedList<User>(userRepository, pageIndex != 0 ? pageIndex - 1 : pageIndex, pageSize == 0 ? 10 : pageSize, predicate); return Negotiate .WithView("Index") .WithMediaRangeModel(MediaRange.FromString("application/json"), new { result = Mapper.Map<IEnumerable<User>, IEnumerable<UserDto>>(users), cnt_whole = users.RecordsFiltered }); }; Get["/Users/Add"] = _ => View["Save", new UserDto()]; Get["/Users/{id:guid}"] = parameters => { var guid = (Guid)parameters.id; var dto = Mapper.Map<User, UserDto>(userRepository.Get(guid)); return View["Save", dto]; }; Get["/Users/Details/{id:guid}"] = parameters => { var guid = (Guid)parameters.id; var dto = Mapper.Map<User, UserDto>(userRepository.Get(guid)); return Response.AsJson(dto); }; Post["/Users"] = _ => { var dto = this.BindAndValidate<UserDto>(); dto.CreatedBy = Context.CurrentUser.UserName; dto.IsActive = true; if (dto.TrialExpiration == null) dto.TrialExpiration = DateTime.UtcNow.Date; if (ModelValidationResult.IsValid) { //var clientUsersDto = this.Bind<List<ClientUserDto>>(); //dto.ClientUsers = clientUsersDto; var entity = Mapper.Map(dto, userRepository.Get(dto.Id) ?? new User()); entity.HashPassword(dto.Password); bus.Publish(new CreateUpdateEntity(entity, "Create")); ////RabbitMQ var metaEntity = Mapper.Map(entity, new UserMessage()); var advancedBus = new TransactionBus(eBus); advancedBus.SendDynamic(metaEntity); return View["Index"]; } return View["Save", dto]; }; Put["/Users/{id}"] = parameters => { var dto = this.BindAndValidate<UserDto>(); dto.ModifiedBy = Context.CurrentUser.UserName; if (dto.ResetPassword != null) { dto.Password = dto.ResetPassword; } if (dto.TrialExpiration == null) dto.TrialExpiration = DateTime.UtcNow.Date; if (ModelValidationResult.IsValid) { //var clientUsersDto = this.Bind<List<ClientUserDto>>(); //dto.ClientUsers = clientUsersDto; var entity = Mapper.Map(dto, userRepository.Get(dto.Id)); if (dto.ResetPassword != null) entity.HashPassword(dto.Password); bus.Publish(new CreateUpdateEntity(entity, "Update")); ////RabbitMQ var metaEntity = Mapper.Map(entity, new UserMessage()); var advancedBus = new TransactionBus(eBus); advancedBus.SendDynamic(metaEntity); return View["Index"]; } return View["Save", dto]; }; Put["/Users/Lock/{id}"] = parameters => { var dto = this.Bind<CustomerDto>(); var entity = userRepository.Get(dto.Id); entity.Modified = DateTime.UtcNow; entity.ModifiedBy = Context.CurrentUser.UserName; entity.Lock(true); bus.Publish(new CreateUpdateEntity(entity, "Update")); return Response.AsJson("User has been locked"); }; Put["/Users/UnLock/{id}"] = parameters => { var dto = this.Bind<CustomerDto>(); var entity = userRepository.Get(dto.Id); entity.Modified = DateTime.UtcNow; entity.ModifiedBy = Context.CurrentUser.UserName; entity.Lock(false); bus.Publish(new CreateUpdateEntity(entity, "Update")); return Response.AsJson("User has been un-locked"); }; Delete["/Users/{id}"] = _ => { this.RequiresAnyClaim(new[] { RoleType.Admin.ToString(), RoleType.ProductManager.ToString(), RoleType.Support.ToString() }); var dto = this.Bind<UserDto>(); var entity = userRepository.Get(dto.Id); bus.Publish(new SoftDeleteEntity(entity)); return Response.AsJson("User has been soft deleted"); }; }