// GET: Layout #region Layout operation public ActionResult Insert() { var model = new LayoutDto(); TempData["InsertModel"] = model; return(View(model)); }
public void DeleteLayout(LayoutDto layout) { var model = _dbContext.Layouts.Find(layout.Id); _dbContext.Layouts.Remove(model); _dbContext.SaveChanges(); }
public LayoutViewModel(LayoutDto dto) { if (dto == null) { Title = string.Empty; Description = string.Empty; Uri = string.Empty; Author = string.Empty; Language = string.Empty; GoogleTagsCode = string.Empty; HeaderContent = string.Empty; FooterContent = string.Empty; return; } Title = dto.Title; Description = dto.Description; Uri = dto.Uri; Author = dto.Author; Language = dto.Language; GoogleTagsCode = dto.GoogleTagsCode; HeaderContent = dto.HeaderContent; FooterContent = dto.FooterContent; }
public ActionResult NewLayout(string Name, Array List) { Service.LayoutService.NewLayout(Name, List); var model = new LayoutDto(); TempData["InsertModel"] = model; return(View("Insert", model)); }
public static Layout MapToLayout(LayoutDto from) { return(new Layout { Description = from.Description, VenueId = from.VenueId }); }
public IActionResult LayoutDesign(int LayoutId) { LayoutDto layoutDto = new LayoutDto(); layoutDto.layoutComponentDtos = _layoutService.GetLayoutComponentList(LayoutId); return(PartialView("PostPartial", layoutDto)); }
public async Task Update(LayoutDto entity) { if (entity == null) { throw new ArgumentNullException(); } if (entity.VenueId <= 0) { throw new LayoutException("VenueId is invalid"); } if (!IsDescriptionUnique(entity, false)) { throw new LayoutException("Area description isn't unique"); } if (entity.AreaList == null || !entity.AreaList.Any()) { throw new LayoutException("Incorrect state of the layout. The layout must have at least one area"); } using (var transaction = CustomTransactionScope.GetTransactionScope()) { var update = await _context.LayoutRepository.GetAsync(entity.Id); update.VenueId = entity.VenueId; update.Description = entity.Description; _context.LayoutRepository.Update(update); await _context.SaveAsync(); var existingAreas = await _context.AreaRepository.FindByAsync(x => x.LayoutId == entity.Id); //find and remove layouts which were deleted existingAreas.Where(list2 => entity.AreaList.All(list1 => list1.Id != list2.Id)).ToList() .ForEach(x => { _context.AreaRepository.Delete(x); }); foreach (var area in entity.AreaList) { if (area.Id == 0) { area.LayoutId = update.Id; await _areaService.Create(area); } else { await _areaService.Update(area); } } transaction.Complete(); } }
public static Layout ToLayoutContract(LayoutDto from) { return(new Layout { Description = from.Description, Id = from.Id, VenueId = from.VenueId, AreaList = from.AreaList?.Select(x => AreaParser.ToAreaContract(x)).ToList() }); }
public async Task <IActionResult> AddPost() { LayoutDto layoutDto = new LayoutDto(); layoutDto.layoutDtos = await _layoutApiClient.GetLayouts(); layoutDto.mainPageDtos = await _mainPageApiClient.GetMainPages(); return(View(layoutDto)); }
public void CreateLayout_WhenModelNotValid_ShouldReturnArgumentException() { var layout = new LayoutDto { Description = "Description", LayoutName = null, VenueId = 1 }; var exception = Assert.Throws <ArgumentException>(() => _venueService.CreateLayout(layout)); Assert.AreEqual("The LayoutName field is required.", exception.Message); }
public void CreateLayout_WhenLayoutNameExists_ShouldReturnValidationException() { var layout = new LayoutDto { Description = "Description", LayoutName = "1 layout name", VenueId = 1 }; var exception = Assert.Throws <ValidationException>(() => _venueService.CreateLayout(layout)); Assert.AreEqual("Layout can't be created for this name", exception.Message); }
public int CreateLayout(LayoutDto layout) { ModelValidation.IsValidModel(layout); if (IsLayoutExist(layout)) { throw new ValidationException("Layout can't be created for this name"); } return(_layoutRepository.Add(_mapper.Map <Layout>(layout))); }
public void CreateLayout_WhenModelValid_ShouldReturnNewId() { var layout = new LayoutDto { Description = "Description", LayoutName = "new layout name", VenueId = 1 }; var result = _venueService.CreateLayout(layout); Assert.AreEqual(result, ReturnIdLayout); }
private bool IsDescriptionUnique(LayoutDto entity, bool isCreating) { var data = from layouts in _context.LayoutRepository.GetList() where layouts.VenueId == entity.VenueId && layouts.Description.Equals(entity.Description, StringComparison.OrdinalIgnoreCase) select layouts; return(isCreating ? !data.Any() : !(from layouts in data where layouts.Id != entity.Id select layouts).Any()); }
public void Create_layout_without_area_excepted_exception() { //Arrange var layoutService = _container.Resolve <ILayoutService>(); var toVenue = 1; var layout = new LayoutDto { Description = "Main hall", VenueId = toVenue, AreaList = new List <AreaDto>() }; //Assert Assert.ThrowsAsync <LayoutException>(async() => await layoutService.Create(layout)); }
public void AddLayout(LayoutDto layout) { if (layout.Name != null) { Layout newLayout = new Layout(); newLayout.Name = layout.Name; newLayout.IsDeleted = false; newLayout.CreateTime = DateTime.Now; _dbContext.Layouts.Add(newLayout); _dbContext.SaveChanges(); } }
public void CreateLayout_WhenLayoutNameExists_ShouldReturnValidationException() { using (var scope = new TransactionScope()) { var layout = new LayoutDto { Description = "Description", LayoutName = "1 layout name", VenueId = 1 }; Assert.Throws <ValidationException>(() => _venueService.CreateLayout(layout)); } }
public void Layout_description_is_unique_expected_exception(string description, int venueId) { //Arrange var layoutService = _container.Resolve <ILayoutService>(); var layout = new LayoutDto() { Description = description, VenueId = venueId }; var exception = Assert.CatchAsync <LayoutException>(async() => await layoutService.Create(layout)); //Assert StringAssert.AreEqualIgnoringCase(exception.Message, "Layout description isn't unique"); }
public async Task <LayoutDto> GetLayoutById(Guid?LayoutId) { if (LayoutId == null) { throw new AggregateRootNotFoundException <LayoutDto>(LayoutId); } var layout = await readContext.SurveyLayout .Include(l => l.SurveyLayoutTag) .Include(l => l.SurveyLayoutQuestion) .AsNoTracking() .FirstOrDefaultAsync(l => l.UID == LayoutId); var surveys = await readContext.Survey .Where(survey => survey.UidLayout == LayoutId) .Select(survey => new SurveyListDto { SurveyName = survey.NmSurvey, EffectiveDate = survey.DtEffective, Icd9 = survey.CdIcd9, OutbreakId = survey.IdOutbreak }) .ToListAsync(); if (layout == null) { throw new AggregateRootNotFoundException <SurveyLayout>(LayoutId); } var items = layout.JsLayout != null?JsonConvert.DeserializeObject <List <LayoutItemDto> >(layout.JsLayout) : new List <LayoutItemDto>(); var questions = await readContext.SurveyQuestionBank .Where(q => layout.SurveyLayoutQuestion.Any(lq => lq.IdQuestion == q.IdQuestion)) .ToListAsync(); await LoadCurrentQuestionInfo(items, questions); var dto = new LayoutDto { LayoutId = layout.UID, LayoutName = layout.NmLayout, Tags = layout.SurveyLayoutTag .Select(x => x.DsTag) .ToList(), Items = items, Surveys = surveys, SavedOn = layout.DtChanged ?? layout.DtAdded }; return(dto); }
public void Layout_description_is_unique(string description, int venueId) { //Arrange var layout = new LayoutDto { Description = description, VenueId = venueId }; var layoutService = _container.Resolve <ILayoutService>(); //Act var exception = Assert.CatchAsync(async() => await layoutService.Create(layout)); //Assert Assert.That(exception.Message, Is.Not.EqualTo("Layout description isn't unique")); }
public void CreateLayout_WhenModelValid_ShouldInsertNewLayout() { using (var scope = new TransactionScope()) { var layout = new LayoutDto { Description = "Description", LayoutName = "new layout name", VenueId = 1 }; var result = _venueService.CreateLayout(layout); layout.Should() .BeEquivalentTo(_venueService.GetLayout(result), options => options.Excluding(x => x.Id)); } }
internal static Layout BuildDomain(this LayoutDto dto) { if (dto == null) { return(null); } return(new Layout { Title = dto.Title, Description = dto.Description, Uri = dto.Uri, Author = dto.Author, Language = dto.Language, GoogleTagsCode = dto.GoogleTagsCode, HeaderContent = dto.HeaderContent, FooterContent = dto.FooterContent }); }
public void Layout_is_valid() { //Arrange var layoutService = _container.Resolve <ILayoutService>(); var toVenue = 1; var layout = new LayoutDto { Description = "Main hall", VenueId = toVenue, AreaList = new List <AreaDto>(), Id = 1 }; layout.AreaList.Add(new AreaDto { Description = "any area description", SeatList = new List <SeatDto>(), Id = 5 }); layout.AreaList.First().SeatList.Add(new SeatDto { Number = 2, Row = 1 }); //Assert Assert.DoesNotThrowAsync(async() => await layoutService.Create(layout)); }
public async Task <bool> Save(LayoutDto layout) { var domain = layout.BuildDomain(); var definition = Builders <Layout> .Update .Set(x => x.Title, domain.Title) .Set(x => x.Description, domain.Description) .Set(x => x.Uri, domain.Uri) .Set(x => x.Author, domain.Author) .Set(x => x.Language, domain.Language) .Set(x => x.GoogleTagsCode, domain.GoogleTagsCode) .Set(x => x.HeaderContent, domain.HeaderContent) .Set(x => x.FooterContent, domain.FooterContent); var options = new UpdateOptions { IsUpsert = true }; var result = await DataCollection().UpdateOneAsync(FilterDefinition <Layout> .Empty, definition, options); _logger.LogInformation($"Site settings were updated"); return(true); }
/// <summary> /// Create a layout. A layout can not be created without areas /// </summary> /// <param name="entity"></param> /// <returns></returns> public async Task Create(LayoutDto entity) { if (entity == null) { throw new ArgumentNullException(); } if (entity.VenueId <= 0) { throw new LayoutException("VenueId is invalid"); } if (!IsDescriptionUnique(entity, true)) { throw new LayoutException("Layout description isn't unique"); } if (entity.AreaList == null || !entity.AreaList.Any()) { throw new LayoutException("Incorrect state of the layout. The layout must have at least one area"); } var layoutAdd = LayoutParser.MapToLayout(entity); using (var transaction = CustomTransactionScope.GetTransactionScope()) { _context.LayoutRepository.Create(layoutAdd); await _context.SaveAsync(); entity.Id = layoutAdd.Id; foreach (var area in entity.AreaList) { area.LayoutId = layoutAdd.Id; await _areaService.Create(area); } transaction.Complete(); } }
public void SaveLayout(LayoutDto layoutDto) { var model = _dbContext.Layouts.Add(new Layout { Name = layoutDto.Name, CreateDate = DateTime.Now }); foreach (var item in layoutDto.layoutComponentDtos) { _dbContext.LayoutComponents.Add(new LayoutComponent { LayoutId = model.Entity.Id, Size = item.Size, Name = item.Name, CreateTime = DateTime.Now, ComponentClass = item.ComponentClass }); } _dbContext.SaveChanges(); }
public LayoutDto EditLayout(LayoutDto input) { return(_layoutManageService.EditLayout(input)); }
public int UpdateLayout(LayoutDto layout) { return(_layoutRepository.Update(_mapper.Map <Layout>(layout))); }
private bool IsLayoutExist(LayoutDto layout) { return(_layoutRepository.GetAll() .Any(x => x.VenueId == layout.VenueId && x.LayoutName == layout.LayoutName)); }
public void UpdateLayout(LayoutDto layout) { throw new NotImplementedException(); }