示例#1
0
        public CreateResultDTO Create(ThemeEditDTO DTO, UserDTO userDTO)
        {
            using (var Data = DataFactory.Get())
            {
                var user    = GetUserService.Get(userDTO, Data);
                var section = Data.SectionRepository.Get().FirstOrDefault(x => x.Id == DTO.SectionId);
                if (section == null)
                {
                    return(CreateResultDTO.NotFound);
                }
                if (ThemeRules.CanCreate(user, section))
                {
                    var theme = new Theme();
                    theme.Messages.Add(
                        new Message
                    {
                        Owner = user,
                        Theme = theme,
                        Time  = DateTime.Now
                    }
                        );

                    EditTheme(theme, DTO);
                    theme.Section = section;

                    Data.ThemeRepository.Add(theme);
                    Data.SaveChanges();
                    return(new CreateResultDTO(theme.Id, AccessCode.Succsess));
                }
                else
                {
                    return(CreateResultDTO.NoPremision);
                }
            }
        }
示例#2
0
        public SectionDTO GetDTO(Section section, User user)
        {
            if (section == null)
            {
                return(null);
            }
            var themes = new List <ThemePreviewDTO>();

            foreach (var theme in section.Themes)
            {
                themes.Add(new ThemePreviewDTO
                {
                    Id           = theme.Id,
                    Pages        = GetThemePages(theme),
                    Name         = theme.Name,
                    Owner        = DTOHelper.GetUser(theme?.Messages?.FirstOrDefault()?.Owner),
                    LastMessages = GetDTO(theme?.Messages?.LastOrDefault(), user)
                });
            }
            return(new SectionDTO
            {
                Id = section.Id,
                Name = section.Name,
                Open = section.Open,
                Themes = themes,
                Route = GetRoute(section),
                Access = new FullAccessDTO
                {
                    CanCreateElements = ThemeRules.CanCreate(user, section),
                    CanDelete = SectionRules.CanDelete(user, section),
                    CanRead = SectionRules.CanRead(user, section),
                    CanUpdate = SectionRules.CanEdit(user, section)
                }
            });
        }