public LogicResponse Create(ModuleDto moduleDto) { Course course = _courseRepository.GetById(moduleDto.CourseId); LogicResponse response = new LogicResponse(); if (course == null) { response.Message = $"No se encontró el curso con id {moduleDto.CourseId}"; response.Success = false; return(response); } Module module = _mapper.Map <ModuleDto, Module>(moduleDto); module.Course = course; try { int id = _moduleRepository.Create(module); response.Message = id.ToString(); response.Success = true; return(response); } catch (Exception ex) { response.Success = false; response.Message = "Error al almacenar el módulo"; return(response); } }
public IEnumerable <IEvent> Handle(CreateModule command) { var module = Module.CreateNew(command, _validator); _moduleRepository.Create(module); return(module.Events); }
public IAggregateRoot Handle(CreateModule command) { var module = Module.CreateNew(command, _validator); _moduleRepository.Create(module); return(module); }
public void Should_save_new_module() { var newModule = ModuleFactory.Module(_siteId, Guid.NewGuid(), Guid.NewGuid(), "Title 3"); _sut.Create(newModule); var actual = _sut.GetById(newModule.Id); Assert.NotNull(actual); }
public async Task <IFormResult <Module> > CreateItem(Module item) { var resultModule = _moduleRepository.Create(item); var result = new FormResult <Module>(resultModule) { IsSucceeded = true, SuccessMessage = "Module has been created" }; return(await Task.FromResult(result)); }
public virtual ActionResult CreateModule(string moduleName, string parentModule) { JsonResponse response = new JsonResponse(); if (string.IsNullOrEmpty(moduleName)) { response.Success = false; response.Message = "You must enter a module name."; response.CssClass = "red"; return(Json(response)); } try { Modules a = new Modules(); a.Id = Guid.NewGuid(); a.ModuleName = moduleName; if (!string.IsNullOrWhiteSpace(parentModule)) { a.ParentModule = parentModule; } moduleRepo.Create(a); if (Request.IsAjaxRequest()) { response.Success = true; response.Message = "Module created successfully!"; response.CssClass = "green"; return(Json(response)); } return(RedirectToAction("Index")); } catch (Exception ex) { if (Request.IsAjaxRequest()) { response.Success = false; response.Message = ex.InnerException.Message; response.CssClass = "red"; return(Json(response)); } ModelState.AddModelError("", ex.InnerException.Message); } return(RedirectToAction("Index")); }
public IEnumerable <IEvent> Handle(AddModule cmd) { var events = new List <IEvent>(); //using (var scope = new TransactionScope(TransactionScopeOption.Suppress)) //{ var page = _pageRepository.GetById(cmd.SiteId, cmd.PageId); if (page == null) { throw new Exception("Page not found"); } var moduleId = Guid.NewGuid(); var module = Module.CreateNew(new CreateModule { SiteId = cmd.SiteId, ModuleTypeId = cmd.ModuleTypeId, Id = moduleId, Title = cmd.Title }, _createModuleValidator); _moduleRepository.Create(module); events.AddRange(module.Events); page.AddModule(new AddPageModule { SiteId = cmd.SiteId, PageId = cmd.PageId, ModuleId = moduleId, PageModuleId = Guid.NewGuid(), Title = cmd.Title, Zone = cmd.Zone, SortOrder = cmd.SortOrder, PageModulePermissions = cmd.PageModulePermissions }, _addPageModuleValidator); events.AddRange(page.Events); _pageRepository.Update(page); // scope.Complete(); //} return(events); }
public IActionResult Post([FromBody] Module module) { try { var result = _moduleRepository.Create(module); if (result != null) { return(Ok(result)); } return(NotFound()); } catch (Exception ex) { _logger.LogError(string.Format("Error occured while creating a Module"), ex); return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public void Should_save_new_module() { var newModule = ModuleFactory.Module(_siteId, Guid.NewGuid(), Guid.NewGuid(), "Title 3"); var newModuleDbEntity = new ModuleDbEntity { SiteId = newModule.SiteId, Id = newModule.Id, Title = newModule.Title }; var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <ModuleDbEntity>(newModule)).Returns(newModuleDbEntity); mapperMock.Setup(x => x.Map <Module>(newModuleDbEntity)).Returns(newModule); _sut = new ModuleRepository(_dbContext, mapperMock.Object); _sut.Create(newModule); var actual = _sut.GetById(newModule.Id); Assert.NotNull(actual); }
public void InstallDefaultSite() { // temporary implementation, it will be based on site templates var siteId = Guid.NewGuid(); var englishLanguageId = Guid.NewGuid(); var mainMenuId = Guid.NewGuid(); var homePageId = Guid.NewGuid(); // ===== Site ===== // var site = Site.CreateNew(new CreateSite { Id = siteId, Name = "Default" }, _createSiteValidator); _siteRepository.Create(site); // ===== Languages ===== // var language = Language.CreateNew(new CreateLanguage { SiteId = siteId, Id = englishLanguageId, Name = "English", CultureName = "en", Url = "en" }, _createLanguageValidator, _languageSortOrderGenerator); _languageRepository.Create(language); // ===== Pages ===== // var homePage = Page.CreateNew(new CreatePage { SiteId = siteId, Id = homePageId, Name = "Home", Url = "home", PageLocalisations = new List <PageLocalisation> { new PageLocalisation { LanguageId = englishLanguageId } }, PagePermissions = new List <PagePermission> { new PagePermission { RoleId = ((int)DefaultRoles.Everyone).ToString(), Type = PermissionType.View } } }, _createPageValidator); homePage.Activate(new ActivatePage { SiteId = siteId, Id = homePageId }, _activatePageValidator); _pageRepository.Create(homePage); // ===== Modules ===== // var textModuleType = _moduleTypeRepository.GetByName("Text"); // Content Zone Module var contentModuleId = Guid.NewGuid(); var contentModule = Module.CreateNew(new CreateModule { SiteId = siteId, ModuleTypeId = textModuleType.Id, Id = contentModuleId, Title = "Content Module" }, _createModuleValidator); _moduleRepository.Create(contentModule); // Left Zone Module var leftModuleId = Guid.NewGuid(); var leftModule = Module.CreateNew(new CreateModule { SiteId = siteId, ModuleTypeId = textModuleType.Id, Id = leftModuleId, Title = "Left Module" }, _createModuleValidator); _moduleRepository.Create(leftModule); // Right Zone Module var rightModuleId = Guid.NewGuid(); var rightModule = Module.CreateNew(new CreateModule { SiteId = siteId, ModuleTypeId = textModuleType.Id, Id = rightModuleId, Title = "Right Module" }, _createModuleValidator); _moduleRepository.Create(rightModule); // Update Home Page homePage.AddModule(new AddPageModule { SiteId = siteId, PageId = homePageId, ModuleId = contentModuleId, Id = Guid.NewGuid(), Title = "Content", Zone = "Content", SortOrder = 1 }, _addPageModuleValidator); homePage.AddModule(new AddPageModule { SiteId = siteId, PageId = homePageId, ModuleId = leftModuleId, Id = Guid.NewGuid(), Title = "Left", Zone = "Left", SortOrder = 1 }, _addPageModuleValidator); homePage.AddModule(new AddPageModule { SiteId = siteId, PageId = homePageId, ModuleId = rightModuleId, Id = Guid.NewGuid(), Title = "Right", Zone = "Right", SortOrder = 1 }, _addPageModuleValidator); _pageRepository.Update(homePage); // ===== Menus ===== // var mainMenu = Menu.CreateNew(new CreateMenu { SiteId = siteId, Id = mainMenuId, Name = "Main" }, _createMenuValidator); mainMenu.AddMenuItem(new AddMenuItem { SiteId = siteId, MenuId = mainMenuId, MenuItemId = Guid.NewGuid(), MenuItemType = MenuItemType.Page, PageId = homePageId, Link = string.Empty, Text = "Home", Title = "Home Page", MenuItemLocalisations = new List <MenuItemDetails.MenuItemLocalisation> { new MenuItemDetails.MenuItemLocalisation { LanguageId = englishLanguageId } } }, _addMenuItemValidator); _menuRepository.Create(mainMenu); }
public void InstallDefaultSite() { var siteId = Guid.NewGuid(); var englishLanguageId = Guid.NewGuid(); var mainMenuId = Guid.NewGuid(); var homePageId = Guid.NewGuid(); // ===== Site ===== // var site = Site.CreateNew(new CreateSite { Id = siteId, Name = "Default" }, _createSiteValidator); _siteRepository.Create(site); // ===== Languages ===== // var language = Language.CreateNew(new CreateLanguage { SiteId = siteId, Id = englishLanguageId, Name = "English", CultureName = "en", Url = "en" }, _createLanguageValidator, _languageSortOrderGenerator); language.Activate(new ActivateLanguage { SiteId = siteId, Id = englishLanguageId }, _activateLanguageValidator); _languageRepository.Create(language); // ===== Pages ===== // var pagePermisisons = new List <PagePermission> { new PagePermission { RoleId = Everyone.Id, Type = PermissionType.View } }; pagePermisisons.Add(new PagePermission { RoleId = Administrator.Id, Type = PermissionType.View }); pagePermisisons.Add(new PagePermission { RoleId = Administrator.Id, Type = PermissionType.Edit }); var homePage = Page.CreateNew(new CreatePage { SiteId = siteId, Id = homePageId, Name = "Home", Url = "home", PageLocalisations = new List <PageLocalisation> { new PageLocalisation { LanguageId = englishLanguageId } }, PagePermissions = pagePermisisons }, _createPageValidator); homePage.Activate(new ActivatePage { SiteId = siteId, Id = homePageId }, _activatePageValidator); _pageRepository.Create(homePage); // ===== Modules ===== // var textModuleType = _moduleTypeRepository.GetByName("Text"); // Content Zone Module var contentModuleId = Guid.NewGuid(); var contentModule = Module.CreateNew(new CreateModule { SiteId = siteId, ModuleTypeId = textModuleType.Id, Id = contentModuleId, Title = "Content Module" }, _createModuleValidator); _moduleRepository.Create(contentModule); // Left Zone Module var leftModuleId = Guid.NewGuid(); var leftModule = Module.CreateNew(new CreateModule { SiteId = siteId, ModuleTypeId = textModuleType.Id, Id = leftModuleId, Title = "Left Module" }, _createModuleValidator); _moduleRepository.Create(leftModule); // Right Zone Module var rightModuleId = Guid.NewGuid(); var rightModule = Module.CreateNew(new CreateModule { SiteId = siteId, ModuleTypeId = textModuleType.Id, Id = rightModuleId, Title = "Right Module" }, _createModuleValidator); _moduleRepository.Create(rightModule); // Update Home Page var pageModulePermisisons = new List <PageModulePermission> { new PageModulePermission { RoleId = Everyone.Id, Type = PermissionType.View } }; pageModulePermisisons.Add(new PageModulePermission { RoleId = Administrator.Id, Type = PermissionType.View }); pageModulePermisisons.Add(new PageModulePermission { RoleId = Administrator.Id, Type = PermissionType.Edit }); homePage.AddModule(new AddPageModule { SiteId = siteId, PageId = homePageId, ModuleId = contentModuleId, PageModuleId = Guid.NewGuid(), Title = "Content", Zone = "Content", SortOrder = 1, PageModulePermissions = pageModulePermisisons }, _addPageModuleValidator); homePage.AddModule(new AddPageModule { SiteId = siteId, PageId = homePageId, ModuleId = leftModuleId, PageModuleId = Guid.NewGuid(), Title = "Left", Zone = "Left", SortOrder = 1, PageModulePermissions = pageModulePermisisons }, _addPageModuleValidator); homePage.AddModule(new AddPageModule { SiteId = siteId, PageId = homePageId, ModuleId = rightModuleId, PageModuleId = Guid.NewGuid(), Title = "Right", Zone = "Right", SortOrder = 1, PageModulePermissions = pageModulePermisisons }, _addPageModuleValidator); _pageRepository.Update(homePage); // ===== Menus ===== // var mainMenu = Menu.CreateNew(new CreateMenu { SiteId = siteId, Id = mainMenuId, Name = "Main" }, _createMenuValidator); mainMenu.AddMenuItem(new AddMenuItem { SiteId = siteId, MenuId = mainMenuId, MenuItemId = Guid.NewGuid(), Type = MenuItemType.Page, PageId = homePageId, Link = string.Empty, Text = "Home", Title = "Home Page", MenuItemLocalisations = new List <MenuItemLocalisation> { new MenuItemLocalisation { LanguageId = englishLanguageId } }, MenuItemPermissions = new List <MenuItemPermission> { new MenuItemPermission { RoleId = Everyone.Id } } }, _addMenuItemValidator); _menuRepository.Create(mainMenu); // ===== Update Site ===== // site.UpdateDetails(new UpdateSiteDetails { SiteId = siteId, HomePageId = homePageId, Title = "Weapsy", MetaDescription = "Weapsy", MetaKeywords = "Weapsy", SiteLocalisations = new List <SiteLocalisation> { new SiteLocalisation { SiteId = siteId, LanguageId = englishLanguageId } } }, _updateSiteDetailsValidator); _siteRepository.Update(site); }
public bool Create(Domain.Module entity) { var flag = _repository.Create(entity); return(flag); }