Exemplo n.º 1
0
        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");
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
 private ICategory CategoryDtoToCategory(ICategoryDto categoryDto)
 {
     return(new Category()
     {
         CategoryId = categoryDto.CategoryId,
         CategoryName = categoryDto.CategoryName,
     });
 }
Exemplo n.º 5
0
 public static Category Create(ICategoryDto dto)
 {
     if (dto == null)
     {
         return(null);
     }
     return(new Category(
                dto.IdCategory,
                dto.Name,
                dto.ParentCategory
                ));
 }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 8
0
 public static Category ToDomainObject(this ICategoryDto dto)
 {
     return(new Category(dto));
 }
Exemplo n.º 9
0
 public Category(ICategoryDto data) : base(data)
 {
 }