예제 #1
0
    public void InsertCategory(string name, string description)
    {
        try
        {
            name        = name.TrimEnd().TrimStart();
            description = description.TrimEnd().TrimStart();
        }
        catch (Exception)
        {
            throw new Exception("No es posible registrar la Categoría");
        }

        CategoriesDAO   dao        = new CategoriesDAO();
        List <Category> categories = GetAllCategories();

        if (categories.FindAll(c => (c.name.ToUpperInvariant().Equals(name.ToUpperInvariant()))).Count > 0)
        {
            throw new Exception("Ya existe una Categoría con este nombre");
        }

        Category newCategory = new Category();

        newCategory.name        = name;
        newCategory.description = description;
        int result = dao.CreateCategory(newCategory);

        if (result < 1)
        {
            throw new Exception("No es posible registrar la Categoría");
        }
    }