public ICategoryDto GetCategoryById(int id) { SqlConnection conn = webShopContext.GetConnection(); ICategoryDto category = null; try { conn.Open(); string sql = "SELECT category_id, category_name FROM category WHERE category_id = @id;"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@id", id); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { category = new CategoryDto() { CategoryId = rdr.GetInt32(0), CategoryName = rdr.GetString(1), }; } rdr.Close(); } catch (Exception e) { throw e; } conn.Close(); return(category); }
public override void Execute(CreateCategoryCommand command) { // Nothing special to do here, permissions have been checked and parameters validated! ICategoryDto category = this.datastore.Create(new Category(command.Name, command.SortOrder, command.Description)); this.SetTaskStatus(command.TaskId, category.Id, "Category"); }
public override void Execute(CreateForumCommand command) { // Nothing special to do here, permissions have been checked and parameters validated! IForumDto forum = null; if (String.IsNullOrWhiteSpace(command.ParentForumId)) { ICategoryDto category = this.categories.ReadById(command.CategoryId); if (category == null) { // TODO: throw new ArgumentException("Given category not found"); } forum = this.forums.Create(new Forum(new Category(category), command.Name, command.SortOrder, command.Description)); } else { IForumDto parentForum = this.forums.ReadById(command.ParentForumId); if (parentForum == null) { // TODO: throw new ArgumentException("Given forum not found"); } forum = this.forums.CreateAsForumChild(new Forum(new Forum(parentForum), command.Name, command.SortOrder, command.Description)); } this.SetTaskStatus(command.TaskId, forum.Id, "Forum"); }
private ICategory CategoryDtoToCategory(ICategoryDto categoryDto) { return(new Category() { CategoryId = categoryDto.CategoryId, CategoryName = categoryDto.CategoryName, }); }
public static Category Create(ICategoryDto dto) { if (dto == null) { return(null); } return(new Category( dto.IdCategory, dto.Name, dto.ParentCategory )); }
public ReadBreadcrumbForForum Handle(ReadBreadcrumbForForumQuery query) { IForumDto forum = this.forumDatastore.ReadById(query.ForumId); ICategoryDto category = this.categoryDatastore.ReadById(forum.Category.Id); IEnumerable <IForumDto> forums = this.forumDatastore.ReadByPath(forum.Path); return(new ReadBreadcrumbForForum { Category = category, Forums = forums }); }
public override void Execute(UpdateCategoryCommand command) { // Permissions have been checked and parameters validated! ICategoryDto dto = this.categories.ReadById(command.Id); if (dto == null) { throw new CategoryNotFoundException(command.Id); } Category c = new Category(dto); c.Name = command.Name; c.SortOrder = command.SortOrder; c.Description = command.Description; c.ClearAndAddProperties(c.Properties); this.categories.Update(c); this.SetTaskStatus(command.TaskId, command.Id, "Category"); }
public static Category ToDomainObject(this ICategoryDto dto) { return(new Category(dto)); }
public Category(ICategoryDto data) : base(data) { }