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);
                }
            }
        }
        private void EditTheme(Theme theme, ThemeEditDTO themeDTO)
        {
            theme.Name = themeDTO.Name;
            theme.Open = themeDTO.Open;
            var fs = theme?.Messages?.FirstOrDefault();

            if (fs == null)
            {
                return;
            }
            fs.Text = themeDTO.Text;
        }
 public AccessCode Update(ThemeEditDTO DTO, UserDTO userDTO)
 {
     using (var Data = DataFactory.Get())
     {
         var check = CheckTheme(userDTO, DTO.Id, ThemeRules.CanEdit, Data);
         if (check.Code == AccessCode.Succsess)
         {
             EditTheme(check.Theme, DTO);
             Data.ThemeRepository.Edited(check.Theme);
             Data.SaveChanges();
         }
         return(check.Code);
     }
 }
Exemple #4
0
        public IActionResult Update(ThemeRequest themeRequest)
        {
            var theme = new ThemeEditDTO
            {
                Name = themeRequest.Name,
                Open = themeRequest.Open,
                Text = themeRequest.Text,
                Id   = themeRequest.Id
            };

            var res = ThemeService.Update(theme, GetUser());

            if (res == AccessCode.Succsess)
            {
                return(RedirectToAction("Index", new { id = themeRequest.Id }));
            }
            else
            {
                return(Redirect(res));
            }
        }