/// <summary>
        /// Creates the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        public int Create(Category instance)
        {
            string sqlStatement = "INSERT [dbo].[Categories]([CategoryName],[Description])";
            sqlStatement += "VALUES(@CategoryName,@Description);";

            using (SqlConnection conn = new SqlConnection(this.ConnectionString))
            using (SqlCommand command = new SqlCommand(sqlStatement, conn))
            {
                command.Parameters.Add(new SqlParameter("CategoryName", instance.CategoryName));
                command.Parameters.Add(new SqlParameter("Description", instance.Description));

                command.CommandType = CommandType.Text;
                command.CommandTimeout = 180;

                if (conn.State != ConnectionState.Open) conn.Open();

                try
                {
                    int result = command.ExecuteNonQuery();
                    return result;
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Example #2
0
        public virtual void AddCategory(Category category)
        {
            if (category == null)
            {
                return;
            }

            Categories.Add(category);
        }
Example #3
0
 public static Data.Models.Category ToEntity(this Domain.Category domain)
 {
     return(new Data.Models.Category()
     {
         Id = domain.Id,
         Name = domain.Name,
         Song = domain.Song.ToEntityList()
     });
 }
 public ActionResult Edit(Category instance)
 {
     if (ModelState.IsValid)
     {
         this._repository.Update(instance);
         return RedirectToAction("Index");
     }
     return View(instance);
 }
Example #5
0
        public Domain.Member Create(string name, Domain.Category category, DateTime birthDate)
        {
            Domain.Member member = new Domain.Member
            {
                Name      = name,
                Category  = category,
                BirthDate = birthDate
            };

            return(member);
        }
 public ActionResult Create(Category model)
 {
     try{
         // TODO: Add insert logic here
         categoryManager.saveCategory(model);
         return RedirectToAction("Index");
     }
     catch{
         return View();
     }
 }
Example #7
0
        public static DAL.App.DTO.DomainLikeDTO.Category MapFromDomain(Domain.Category category)
        {
            var res = category == null ? null : new DAL.App.DTO.DomainLikeDTO.Category
            {
                Id           = category.Id,
                CategoryName = category.CategoryName.Translate(),
                ShopId       = category.ShopId,
                Shop         = ShopMapper.MapFromDomain(category.Shop)
            };

            if (category?.ProductsInCategory != null)
            {
                res.ProductsInCategory = category.ProductsInCategory.Select(e => ProductInCategoryMapper.MapFromDomain(e)).ToList();
            }

            return(res);
        }
Example #8
0
 public IEnumerable<Category> ReadAllCatergories()
 {
     string query = "SELECT Id, Description FROM Categories";
       List<Category> categories = new List<Category>();
       using (SqlConnection conn = GetConnection())
       {
     //Toewijzen van zowel query alsook de connectie aan het commando object
     SqlCommand cmd = new SqlCommand(query, conn);
     conn.Open();
     //Commando uitvoeren op de DB en de resultatentabel uitlezen via onze
     //DataReader cursor
     SqlDataReader reader = cmd.ExecuteReader();
     while (reader.Read())
     {
       Category loadingCategory = new Category();
       loadingCategory.CategoryId = reader.GetInt32(0);
       loadingCategory.Description = reader.GetString(1);
       categories.Add(loadingCategory);
     }
     reader.Close();
     conn.Close();
       }
       return categories;
 }
        /// <summary>
        /// Updates the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        public int Update(Category instance)
        {
            string sqlStatement = "UPDATE [dbo].[Categories] ";
            sqlStatement += "SET ";
            sqlStatement += "[CategoryName] = @CategoryName, ";
            sqlStatement += "[Description] = @Description ";
            sqlStatement += "WHERE [dbo].[Categories].[CategoryID] = @CategoryID;";

            using (SqlConnection conn = new SqlConnection(this.ConnectionString))
            using (SqlCommand command = new SqlCommand(sqlStatement, conn))
            {
                command.Parameters.Add(new SqlParameter("CategoryName", instance.CategoryName));
                command.Parameters.Add(new SqlParameter("Description", instance.Description));
                command.Parameters.Add(new SqlParameter("CategoryID", instance.CategoryID));

                command.CommandType = CommandType.Text;
                command.CommandTimeout = 180;

                if (conn.State != ConnectionState.Open) conn.Open();

                try
                {
                    int result = command.ExecuteNonQuery();
                    return result;
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
 internal void RemoveCategory(Category category)
 {
     RemoveObject(Relation.VerbType.CategorizedAs, category);
 }
Example #11
0
 public Product(Category category, decimal price, string description)
 {
     this.Category = category;
     this.Price = price;
     this.Description = description;
 }
Example #12
0
        /// <summary>
        /// Gets the one.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Category GetOne(int id)
        {
            string sqlStatement = "select * from Categories where CategoryID = @CategoryID";

            Category item = new Category();

            using (SqlConnection conn = new SqlConnection(this.ConnectionString))
            using (SqlCommand comm = new SqlCommand(sqlStatement, conn))
            {
                comm.Parameters.Add(new SqlParameter("CategoryID", id));

                comm.CommandType = CommandType.Text;
                comm.CommandTimeout = 180;

                if (conn.State != ConnectionState.Open) conn.Open();

                using (IDataReader reader = comm.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        item.CategoryID = int.Parse(reader["CategoryID"].ToString());
                        item.CategoryName = reader["CategoryName"].ToString();
                        item.Description = reader["Description"].ToString();
                    }
                }
            }
            return item;
        }
Example #13
0
 public void addCategory()
 {
     string expectedName = "Coffe";
     Category c = new Category { Description = expectedName };
     Assert.AreEqual(expectedName, c.Description);
 }
 public void saveCategory(Category c)
 {
     NHibernateHelper.Save(c);
     NHibernateHelper.Commit();
 }
 internal void AddCategory(Category category)
 {
     AddObject(Relation.VerbType.CategorizedAs, category);
 }
Example #16
0
        public void fetchProductWithInvalidId()
        {
            Category c = new Category();
            try
            {

                c.FetchProduct(new Guid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
            }
            catch (BusinessRuleException b)
            {
                StringAssert.Contains(b.Message, c.invalidProductId);
                return;
            }
            Assert.Fail("No exception was thrown.");
        }
Example #17
0
        /// <summary>
        /// Gets the categories.
        /// </summary>
        /// <returns></returns>
        public List<Category> GetCategories()
        {
            List<Category> categories = new List<Category>();

            string sqlStatement = "select * from Categories order by CategoryID desc";

            using (SqlConnection conn = new SqlConnection(this.ConnectionString))
            using (SqlCommand command = new SqlCommand(sqlStatement, conn))
            {
                command.CommandType = CommandType.Text;
                command.CommandTimeout = 180;

                if (conn.State != ConnectionState.Open) conn.Open();

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Category item = new Category();
                        item.CategoryID = int.Parse(reader["CategoryID"].ToString());
                        item.CategoryName = reader["CategoryName"].ToString();
                        item.Description = reader["Description"].ToString();

                        categories.Add(item);
                    }
                }
            }
            return categories;
        }
Example #18
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Category category = new Category
            {
                System_Created = DateTime.Now,
            };

            if (!string.IsNullOrEmpty(this.lblId.Text))
                category = this.View_QueryResults
                    .Where(x => x.Id == int.Parse(this.lblId.Text))
                    .FirstOrDefault();

            category.Name = this.txtCategoryName.Text;
            category.ShowInSummary = this.chkShowInSummary.Checked;
            category.SystemUpdateDateTime = DateTime.Now;

            this.View_SaveRecord(category);
            this.View_QueryRecords(null);
            this.WindowInputChanges(ModifierState.Save);
        }
Example #19
0
 public ICategory AddCategory(string description)
 {
     var category = new Category(description);
     _context.Categories.Add(category);
     _context.SaveChanges();
     return category;
 }