public Form ToForm() { var formId = Guid.NewGuid(); var sections = SectionRules?.Select(sr => sr.ToSection(formId)).ToList(); Dictionary <Guid, Guid> mapQuestions = new Dictionary <Guid, Guid>(); List <FormItem> items = new List <FormItem>(); Questions?.ForEach((question) => { FormItem item = question.ToFormItem(formId, sections); mapQuestions.Add(question.Id, item.Id); items.Add(item); }); sections.ForEach((section) => { if (section.VisibleCondition != null) { FormFilterCondition.MapVisibleConditionQuestionToItemId(section.VisibleCondition, mapQuestions); } }); items.ForEach((item) => { if (item.VisibleCondition != null) { FormFilterCondition.MapVisibleConditionQuestionToItemId(item.VisibleCondition, mapQuestions); } }); return(new Form { Id = formId, TemplateId = Id, Subject = Subject, MustDisplayElementsCode = MustDisplayElementsCode, Type = Type, Language = Language, Sections = sections, Items = items, IsSignatureAllowed = IsSignatureAllowed, }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //---------------------------------------------------- IConfigService configService = new XMLConfigService("Config.xml"); IMessenger messenger_sms = new SmsMessenger(); IMessenger messenger_email = new EmailMessenger(); IPassHasher passHasher = new SHA256Hasher(); IKeyGenerator smallKeyGenerator = new SmallKeyGenerator(); IKeyGenerator bigKeyGenerator = new BigKeyGenerator(); IRegValidator regValidator = new RegValidator(); IUOWFactory UOWFactory = new EFUOWFactory(configService.ConnectionString); IGetUserDTO getUserDTO = new GetUserDTO(); //---------------------------------------------------- IClaimService claimService = new ClaimService(UOWFactory); //---------------------------------------------------- services.AddSingleton <IConfigService, IConfigService>( serviceProvider => { return(configService); } ); //---------------------------------------------------- services.AddSingleton <IGetUserDTO, IGetUserDTO>( serviceProvider => { return(getUserDTO); } ); //---------------------------------------------------- services.AddSingleton <IUOWFactory, IUOWFactory>( serviceProvider => { return(UOWFactory); } ); services.AddSingleton <IClaimService, ClaimService>(); //----------------------------------------------------- services.AddSingleton <IUserService, UserAuthService>( serviceProvider => { return(new UserAuthService( UOWFactory, new AuthKeyService(smallKeyGenerator, messenger_sms), new AuthKeyService(smallKeyGenerator, messenger_email), passHasher, regValidator, claimService, bigKeyGenerator, getUserDTO )); } ); services.AddSingleton <IProfileService, ProfileService>( serviceProvider => { IConfirmService emailCS = new ConfirmService( new ConfirmKeyService(bigKeyGenerator, messenger_email) ); IConfirmService phoneCS = new ConfirmService( new ConfirmKeyService(smallKeyGenerator, messenger_sms) ); return(new ProfileService( UOWFactory, regValidator, emailCS, phoneCS, passHasher, claimService, getUserDTO )); } ); services.AddSingleton <IRestorePasswordService, RestorePasswordService>( serviceProvider => { var emaiCKS = new ConfirmKeyService(bigKeyGenerator, messenger_email); var phoneCKS = new ConfirmKeyService(smallKeyGenerator, messenger_sms); return(new RestorePasswordService(UOWFactory, emaiCKS, phoneCKS, new RegValidator(), passHasher)); } ); //---------Forum Services-------------------------------- IGroupRules groupRules = new GroupRules(); ISectionRules sectionRules = new SectionRules(groupRules); IThemeRules themeRules = new ThemeRules(sectionRules); IMessageRules messageRules = new MessageRules(themeRules, sectionRules); IDTOHelper dtoHelper = new DTOHelper(); IForumDTOHelper forumDTOHelper = new ForumDTOHelper(messageRules, themeRules, sectionRules, groupRules, dtoHelper); services.AddSingleton <IGroupService, GroupService>( serviceProvider => { return(new GroupService(groupRules, getUserDTO, UOWFactory, forumDTOHelper)); } ); services.AddSingleton <ISectionService, SectionService>( serviceProvider => { return(new SectionService(sectionRules, getUserDTO, UOWFactory, forumDTOHelper)); } ); services.AddSingleton <IThemeService, ThemeService>( serviceProvider => { return(new ThemeService(themeRules, getUserDTO, UOWFactory, forumDTOHelper)); } ); services.AddSingleton <IMessageService, MessageService>( serviceProvider => { return(new MessageService(messageRules, getUserDTO, UOWFactory, forumDTOHelper)); } ); services.AddSingleton <IForumService, ForumService>( serviceProvider => { return(new ForumService(getUserDTO, UOWFactory, forumDTOHelper, groupRules)); } ); //--------------------Page Services-------------------- IPageRules pageRules = new PageRules(); INoteRules noteRules = new NoteRules(); services.AddSingleton <IPageService, PageService>( serviceProvider => { return(new PageService(pageRules, UOWFactory, getUserDTO, dtoHelper)); } ); services.AddSingleton <IBlogService, BlogService>( serviceProvider => { return(new BlogService(noteRules, UOWFactory, getUserDTO, dtoHelper)); } ); //------------------------------------------------------- services.AddSingleton <IImageService, ImageService>( serviceProvider => { return(new ImageService(UOWFactory, getUserDTO)); } ); //------------------------------------------- services.AddSingleton <IAdminService, AdminService>( serviceProvider => { return(new AdminService(getUserDTO, UOWFactory)); } ); services.Configure <FormOptions>(x => { x.ValueCountLimit = int.MaxValue; x.MemoryBufferThreshold = int.MaxValue; x.ValueLengthLimit = int.MaxValue; x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart }); //------------------------------------------------------ services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = new Microsoft.AspNetCore.Http.PathString("/Account/Login"); options.LogoutPath = new Microsoft.AspNetCore.Http.PathString("/Account/Logout"); options.Events.OnValidatePrincipal = PrincipalValidator.ValidateAsync; }); services.AddMvc(); }