Exemple #1
0
        public static List <ThemeDTO> FlattenThemesTree(IEnumerable <Themes> themes, int depth = 0, ThemeDTO parentTheme = null)
        {
            if (themes == null)
            {
                return(null);
            }

            var result = new List <ThemeDTO>();

            foreach (var theme in themes)
            {
                var t = new ThemeDTO
                {
                    Id        = theme.Id,
                    Name      = theme.Name,
                    TreeDepth = depth
                };

                if (parentTheme != null)
                {
                    t.ParentThemesIds.AddRange(parentTheme.ParentThemesIds);
                    t.ParentThemesIds.Add(parentTheme.Id);
                }

                result.Add(t);

                result.AddRange(FlattenThemesTree(theme.InverseParentTheme, depth + 1, t));
            }

            return(result);
        }
Exemple #2
0
        public async Task <ActionResult> CreateTheme(ThemeModel model)
        {
            ThemeDTO themeDto = new ThemeDTO {
                ThemeDesc = model.ThemeDesc, ThemeTitle = model.ThemeTitle, Id = RandomStringIdGenerator.GetUniqueId()
            };
            await ThemeService.CreateNew(themeDto);

            return(RedirectToAction("Index", "Home"));
        }
Exemple #3
0
        private int CountParentElements(ThemeDTO theme)
        {
            if (theme.ParentTheme == null)
            {
                return(0);
            }

            return(1 + this.CountParentElements(theme));
        }
Exemple #4
0
        public async Task <ActionResult> EditTheme(string id)
        {
            ThemeDTO theme = await ThemeService.FindThemeDtoById(id);

            if (theme != null)
            {
                return(View(theme));
            }
            return(HttpNotFound());
        }
Exemple #5
0
        public async Task <ThemeDTO> FindThemeDtoById(string id)
        {
            Theme theme = await Database.ThemeManager.GetById(id);

            ThemeDTO dto = new ThemeDTO {
                Id = theme.Id, ThemeTitle = theme.ThemeTitle, ThemeDesc = theme.ThemeDesc
            };

            return(dto);
        }
Exemple #6
0
        public async Task UpdateAsync(int id, ThemeDTO updatedTheme)
        {
            var theme = await unitOfWork.Themes.GetByIdAsync(id);

            theme.Text  = updatedTheme.Text;
            theme.Title = updatedTheme.Title;
            await SetHashtagsToTheme(theme, updatedTheme.Hashtags);

            unitOfWork.Themes.Update(theme);
            await unitOfWork.SaveAsync();
        }
        public ActionResult <Theme> PostTheme(ThemeDTO theme)
        {
            Theme newTheme = new Theme()
            {
                Title = theme.Title
            };

            _themeRepository.Add(newTheme);
            _themeRepository.SaveChanges();

            return(CreatedAtAction(nameof(GetAllThemes), new { id = newTheme.Id }, newTheme));
        }
Exemple #8
0
        public async Task <IActionResult> Update(ThemeModel themeModel)
        {
            ThemeDTO theme = await _themeService.GetByIdAsync(themeModel.Id);

            if (theme != null)
            {
                theme.Title = themeModel.Title;
                _themeService.Update(theme);

                return(Ok("Success!"));
            }

            return(BadRequest("Theme not found!"));
        }
        public ThemeDTO GetImagePath()
        {
            var themeID = string.IsNullOrWhiteSpace(WebConfigurationManager.AppSettings["CurrentTheme"]) ? "Default" : WebConfigurationManager.AppSettings["CurrentTheme"];

            Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Theme." + themeID).FirstOrDefault();

            System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("Theme." + themeID + ".Theme", assembly);

            ThemeDTO theme = new ThemeDTO();

            theme.LogoImage = resourceManager.GetString("LogoImage");

            return(theme);
        }
Exemple #10
0
        public async Task <ActionResult <ThemeDTO> > UpdateTheme(int id, ThemeDTO theme)
        {
            if (!themeService.IsThemeExist(id))
            {
                return(await CreateThemeAsync(mapper.Map <CreateThemeVM>(theme)));
            }
            if (!themeService.UserIsAuthor(id, GetCurrentUserId()))
            {
                return(Unauthorized());
            }
            await themeService.UpdateAsync(id, theme);

            return(Ok());
        }
Exemple #11
0
        /// <summary>
        /// The convert DTO.
        /// </summary>
        /// <param name="q">
        /// The result DTO.
        /// </param>
        /// <param name="instance">
        /// The instance.
        /// </param>
        /// <returns>
        /// The <see cref="Theme"/>.
        /// </returns>
        private Theme ConvertDto(ThemeDTO q, Theme instance)
        {
            instance           = instance ?? new Theme();
            instance.IsActive  = q.isActive;
            instance.ThemeName = q.themeName;
            if (instance.IsTransient())
            {
                instance.DateCreated = DateTime.Now;
            }

            instance.DateModified = DateTime.Now;
            instance.ModifiedBy   = q.modifiedBy.HasValue ? this.UserModel.GetOneById(q.modifiedBy.Value).Value : null;
            instance.CreatedBy    = q.createdBy.HasValue ? this.UserModel.GetOneById(q.createdBy.Value).Value : null;
            return(instance);
        }
Exemple #12
0
        public async Task <IActionResult> GetById(string theme_id)
        {
            if (int.TryParse(theme_id, out int theme_id_parsed))
            {
                ThemeDTO theme = await _themeService.GetByIdAsync(theme_id_parsed);

                if (theme != null)
                {
                    return(Ok(theme));
                }

                return(BadRequest("Theme not found!"));
            }

            return(BadRequest("Wrong identifier!"));
        }
Exemple #13
0
 public IHttpActionResult InsertNewTheme([FromBody] NewThemeBindingModel newTheme)
 {
     if (ModelState.IsValid)
     {
         ThemeDTO t = new ThemeDTO();
         t.CreateDate = DateTime.Now;
         t.Title      = newTheme.ThemeName;
         t.SectionId  = newTheme.SectionId;
         this.themeService.Insert(t);
         return(Ok());
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Exemple #14
0
 public IHttpActionResult UpdateTheme([FromBody] ThemeToUpdateBindingModel themetoUpdate)
 {
     if (ModelState.IsValid)
     {
         ThemeDTO t = new ThemeDTO();
         t.Id         = themetoUpdate.Id;
         t.CreateDate = themetoUpdate.CreateDate;
         t.Title      = themetoUpdate.Title;
         t.SectionId  = themetoUpdate.SectionId;
         this.themeService.Update(t);
         return(Ok());
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Exemple #15
0
        public ThemeDTO GetImagePath(string themeID)
        {
            if (string.IsNullOrWhiteSpace(themeID))
            {
                themeID = "Default";
            }

            Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Theme." + themeID).FirstOrDefault();

            System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("Theme." + themeID + ".Theme", assembly);

            ThemeDTO theme = new ThemeDTO();

            theme.LogoImage = resourceManager.GetString("LogoImage");

            return(theme);
        }
Exemple #16
0
        public async Task <OperationDetails> Delete(ThemeDTO themeDTO)
        {
            Theme theme = await Database.ThemeManager.GetById(themeDTO.Id);

            if (theme != null)
            {
                await Database.ThemeManager.Delete(theme);

                await Database.SaveAsync();

                return(new OperationDetails(true, "Тема видалено успішно!", ""));
            }
            else
            {
                return(new OperationDetails(true, "Сталася помилка!", ""));
            }
        }
Exemple #17
0
        public async Task <OperationDetails> Edit(ThemeDTO themeDTO)
        {
            Theme theme = await Database.ThemeManager.GetById(themeDTO.Id);

            if (theme != null)
            {
                theme.ThemeTitle = themeDTO.ThemeTitle;
                theme.ThemeDesc  = themeDTO.ThemeDesc;
                await Database.SaveAsync();

                return(new OperationDetails(true, "Тема відредаговано успішно!", ""));
            }
            else
            {
                return(new OperationDetails(true, "Сталася помилка!", ""));
            }
        }
Exemple #18
0
        public async Task <ActionResult> RemoveTheme(string id)
        {
            ThemeDTO theme = await ThemeService.FindThemeDtoById(id);

            try
            {
                if (theme != null)
                {
                    await ThemeService.Delete(theme);
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("Error", "Home"));
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemple #19
0
        public async Task <IActionResult> DeleteFromDatabase(string theme_id)
        {
            if (int.TryParse(theme_id, out int theme_id_parsed))
            {
                ThemeDTO theme = await _themeService.GetByIdAsync(theme_id_parsed);

                if (theme != null)
                {
                    await _themeService.DeleteAsync(theme.Id);

                    return(Ok("Success!"));
                }

                return(BadRequest("Theme not found!"));
            }

            return(BadRequest("Wrong identifier!"));
        }
Exemple #20
0
        /// <summary>
        /// The save update.
        /// </summary>
        /// <param name="resultDto">
        /// The user.
        /// </param>
        /// <returns>
        /// The <see cref="ThemeDTO"/>.
        /// </returns>
        public ThemeDTO Save(ThemeDTO resultDto)
        {
            ValidationResult validationResult;

            if (this.IsValid(resultDto, out validationResult))
            {
                var themeModel  = this.ThemeModel;
                var isTransient = resultDto.themeId == 0;
                var theme       = isTransient ? null : themeModel.GetOneById(resultDto.themeId).Value;
                theme = this.ConvertDto(resultDto, theme);
                themeModel.RegisterSave(theme);
                return(new ThemeDTO(theme));
            }

            var error = this.GenerateValidationError(validationResult);

            this.LogError("Theme.Save", error);
            throw new FaultException <Error>(error, error.errorMessage);
        }
Exemple #21
0
        private ThemeDTO MapTheme(Themes t, int depth = 0)
        {
            if (t == null)
            {
                return(null);
            }

            var result = new ThemeDTO
            {
                Id            = t.Id,
                Name          = t.Name,
                PreviousTheme = this.MapNullableTheme(t.PreviousTheme),
                ParentTheme   = this.MapNullableTheme(t.ParentTheme),
                TreeDepth     = depth,
                ChildThemes   = new ObservableCollection <ThemeDTO>(t.InverseParentTheme
                                                                    .Select(th => this.MapTheme(th, depth + 1)))
            };

            return(result);
        }
        public ThemeDTO GetText([FromUri] IEnumerable <string> keys)
        {
            var themeID = string.IsNullOrWhiteSpace(WebConfigurationManager.AppSettings["CurrentTheme"]) ? "Default" : WebConfigurationManager.AppSettings["CurrentTheme"];

            Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Theme." + themeID).FirstOrDefault();

            System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("Theme." + themeID + ".Theme", assembly);


            ThemeDTO theme = new ThemeDTO();
            Type     type  = theme.GetType();

            foreach (string name in keys)
            {
                string       val  = resourceManager.GetString(name);
                PropertyInfo prop = type.GetProperty(name);
                prop.SetValue(theme, val);
            }

            return(theme);
        }
Exemple #23
0
        public async Task <ICollection <ThemeDTO> > GetAllThemes()
        {
            IEnumerable <Theme> replies = await Database.ThemeManager.GetAll();

            ICollection <ThemeDTO> list = new List <ThemeDTO>();
            ThemeDTO dTO;

            foreach (Theme item in replies)
            {
                dTO = new ThemeDTO
                {
                    Id         = item.Id,
                    ThemeTitle = item.ThemeTitle,
                    ThemeDesc  = item.ThemeDesc
                };
                list.Add(dTO);
            }


            return(list);
        }
Exemple #24
0
        public async Task <OperationDetails> CreateNew(ThemeDTO themeDTO)
        {
            Theme theme = await Database.ThemeManager.GetById(themeDTO.Id);

            if (theme == null)
            {
                theme = new Theme
                {
                    ThemeTitle = themeDTO.ThemeTitle,
                    ThemeDesc  = themeDTO.ThemeDesc,
                    Id         = themeDTO.Id
                };
                await Database.ThemeManager.Create(theme);

                await Database.SaveAsync();

                return(new OperationDetails(true, "Тему додано успішно!", ""));
            }
            else
            {
                return(new OperationDetails(false, "Сталася помилка", ""));
            }
        }
Exemple #25
0
        public async Task <ThemeDTO> CreateAsync(ThemeDTO themeDTO, int authorId)
        {
            var themeToCreate = mapper.Map <Theme>(themeDTO);

            themeToCreate.AuthorId = authorId;
            themeToCreate.DateTime = DateTime.Now;
            var createdTheme = await unitOfWork.Themes.CreateAsync(themeToCreate);

            await unitOfWork.SaveAsync();

            foreach (var hashtagText in themeDTO.Hashtags)
            {
                var hashtag = unitOfWork.Hashtags.GetAll(h => h.Text == hashtagText).FirstOrDefault();
                if (hashtag == null)
                {
                    hashtag = await unitOfWork.Hashtags.CreateAsync(new Hashtag { Text = hashtagText });

                    await unitOfWork.SaveAsync();
                }
                await unitOfWork.ThemeHashtags.CreateAsync(new ThemeHashtag
                {
                    ThemeId   = createdTheme.Id,
                    HashtagId = hashtag.Id
                }
                                                           );
            }

            await unitOfWork.SaveAsync();


            createdTheme = unitOfWork.Themes.GetAll(th => th.Id == createdTheme.Id).Include(th => th.Author).First();
            var createdthemeDTO = mapper.Map <ThemeDTO>(createdTheme);

            createdthemeDTO.Author.MessageCount = messageService.GetMessageCountForUser(createdTheme.AuthorId.Value);

            return(createdthemeDTO);
        }
Exemple #26
0
		public async Task<IHttpActionResult> AddTheme(ThemeDTO model)
		{
			if (ModelState.IsValid)
			{
				try
				{
					if (model.School == null)
					{
						var school = await _schoolService.GetDTO(model.SchoolId);
						model.School = school;
					}
					await _themeService.Save(model);
					return this.Ok();
				}
				catch (Exception ex)
				{
					return this.BadRequest(ex.Message);
				}
			}
			else
			{
				return this.BadRequest(ModelState);
			}
		}
Exemple #27
0
        public async Task <IActionResult> SoftDelete(string theme_id)
        {
            if (int.TryParse(theme_id, out int theme_id_parsed))
            {
                ThemeDTO theme = await _themeService.GetByIdAsync(theme_id_parsed);

                if (theme != null)
                {
                    if (theme.IsDeleted)
                    {
                        return(BadRequest("Theme already deleted!"));
                    }

                    theme.IsDeleted = true;
                    _themeService.Update(theme);

                    return(Ok("Success!"));
                }

                return(BadRequest("Theme not found!"));
            }

            return(BadRequest("Wrong identifier!"));
        }
Exemple #28
0
 public ThemeControl(int sectionId, ThemeDTO themeDTO)
 {
     SectionId = sectionId;
     ThemeDTO  = themeDTO;
 }
Exemple #29
0
 void IThemeService.Insert(ThemeDTO newTheme)
 {
     DAL.Models.Theme theme = this.mapper.Map <DAL.Models.Theme>(newTheme);
     this.unitOfWork.Themes.Insert(theme);
     this.unitOfWork.Save();
 }
Exemple #30
0
        public async Task <ActionResult> EditTheme(ThemeDTO theme)
        {
            await ThemeService.Edit(theme);

            return(RedirectToAction("DisplayThemes"));
        }
Exemple #31
0
		public async Task<IHttpActionResult> ModifyUser(ThemeDTO model)
		{
			if (ModelState.IsValid)
			{
				try
				{
					await _themeService.Save(model);
					return this.Ok();
				}
				catch (Exception ex)
				{
					return this.BadRequest(ex.Message);
				}
			}
			else
			{
				return this.BadRequest(ModelState);
			}
		}
Exemple #32
0
 void IThemeService.Update(ThemeDTO themeToUpdate)
 {
     DAL.Models.Theme theme = this.mapper.Map <DAL.Models.Theme>(themeToUpdate);
     this.unitOfWork.Themes.Update(theme);
     this.unitOfWork.Save();
 }