Exemplo n.º 1
0
        // GET: Layout
        #region Layout operation
        public ActionResult Insert()
        {
            var model = new LayoutDto();

            TempData["InsertModel"] = model;
            return(View(model));
        }
Exemplo n.º 2
0
        public void DeleteLayout(LayoutDto layout)
        {
            var model = _dbContext.Layouts.Find(layout.Id);

            _dbContext.Layouts.Remove(model);
            _dbContext.SaveChanges();
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        public ActionResult NewLayout(string Name, Array List)
        {
            Service.LayoutService.NewLayout(Name, List);
            var model = new LayoutDto();

            TempData["InsertModel"] = model;
            return(View("Insert", model));
        }
Exemplo n.º 5
0
 public static Layout MapToLayout(LayoutDto from)
 {
     return(new Layout
     {
         Description = from.Description,
         VenueId = from.VenueId
     });
 }
Exemplo n.º 6
0
        public IActionResult LayoutDesign(int LayoutId)
        {
            LayoutDto layoutDto = new LayoutDto();

            layoutDto.layoutComponentDtos = _layoutService.GetLayoutComponentList(LayoutId);

            return(PartialView("PostPartial", layoutDto));
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
 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()
     });
 }
Exemplo n.º 9
0
        public async Task <IActionResult> AddPost()
        {
            LayoutDto layoutDto = new LayoutDto();

            layoutDto.layoutDtos = await _layoutApiClient.GetLayouts();

            layoutDto.mainPageDtos = await _mainPageApiClient.GetMainPages();


            return(View(layoutDto));
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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)));
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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());
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
 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();
     }
 }
Exemplo n.º 17
0
        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));
            }
        }
Exemplo n.º 18
0
        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");
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
        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"));
        }
Exemplo n.º 21
0
        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));
            }
        }
Exemplo n.º 22
0
        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
            });
        }
Exemplo n.º 23
0
        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));
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        /// <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();
            }
        }
Exemplo n.º 26
0
        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));
 }
Exemplo n.º 28
0
 public int UpdateLayout(LayoutDto layout)
 {
     return(_layoutRepository.Update(_mapper.Map <Layout>(layout)));
 }
Exemplo n.º 29
0
 private bool IsLayoutExist(LayoutDto layout)
 {
     return(_layoutRepository.GetAll()
            .Any(x => x.VenueId == layout.VenueId && x.LayoutName == layout.LayoutName));
 }
Exemplo n.º 30
0
 public void UpdateLayout(LayoutDto layout)
 {
     throw new NotImplementedException();
 }