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); }
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")); }
private int CountParentElements(ThemeDTO theme) { if (theme.ParentTheme == null) { return(0); } return(1 + this.CountParentElements(theme)); }
public async Task <ActionResult> EditTheme(string id) { ThemeDTO theme = await ThemeService.FindThemeDtoById(id); if (theme != null) { return(View(theme)); } return(HttpNotFound()); }
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); }
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)); }
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); }
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()); }
/// <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); }
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!")); }
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)); } }
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)); } }
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); }
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, "Сталася помилка!", "")); } }
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, "Сталася помилка!", "")); } }
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")); }
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!")); }
/// <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); }
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); }
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); }
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, "Сталася помилка", "")); } }
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); }
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); } }
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!")); }
public ThemeControl(int sectionId, ThemeDTO themeDTO) { SectionId = sectionId; ThemeDTO = themeDTO; }
void IThemeService.Insert(ThemeDTO newTheme) { DAL.Models.Theme theme = this.mapper.Map <DAL.Models.Theme>(newTheme); this.unitOfWork.Themes.Insert(theme); this.unitOfWork.Save(); }
public async Task <ActionResult> EditTheme(ThemeDTO theme) { await ThemeService.Edit(theme); return(RedirectToAction("DisplayThemes")); }
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); } }
void IThemeService.Update(ThemeDTO themeToUpdate) { DAL.Models.Theme theme = this.mapper.Map <DAL.Models.Theme>(themeToUpdate); this.unitOfWork.Themes.Update(theme); this.unitOfWork.Save(); }