Ejemplo n.º 1
0
 public CreateResultDTO Create(MessageEditDTO DTO, UserDTO userDTO)
 {
     using (var Data = DataFactory.Get())
     {
         var user  = GetUserService.Get(userDTO, Data);
         var theme = Data.ThemeRepository.Get().FirstOrDefault(x => x.Id == DTO.ThemeId);
         if (theme == null)
         {
             return(CreateResultDTO.NotFound);
         }
         if (MessageRules.CanCreate(user, theme))
         {
             var message = new Message();
             EditMessage(message, DTO, user, false);
             message.Theme = theme;
             Data.MessageRepository.Add(message);
             Data.SaveChanges();
             return(new CreateResultDTO(message.Id, AccessCode.Succsess));
         }
         else
         {
             return(CreateResultDTO.NoPremision);
         }
     }
 }
Ejemplo n.º 2
0
        private ThemeDTO CreateThemeDTO(Theme theme, User user, IEnumerable <Message> messages)
        {
            var mres = new List <MessageDTO>();

            foreach (var message in messages)
            {
                mres.Add(GetDTO(message, user));
            }
            return(new ThemeDTO
            {
                Name = theme.Name,
                Open = theme.Open,
                Messages = mres,
                Id = theme.Id,
                Route = GetRoute(theme),
                Access = new FullAccessDTO
                {
                    CanCreateElements = MessageRules.CanCreate(user, theme),
                    CanDelete = ThemeRules.CanDelete(user, theme),
                    CanRead = ThemeRules.CanRead(user, theme),
                    CanUpdate = ThemeRules.CanEdit(user, theme)
                }
            });
        }