public CategoryDTO GetCategoryById(int id) { using (var entities = new CategoryDAL()) { var cat = entities.tblCategories.FirstOrDefault(c => c.id == id); return(_mapper.Map <CategoryDTO>(cat)); } }
public List <CategoryDTO> GetCategories() { List <CategoryDTO> category = new List <CategoryDTO>(); using (var entities = new CategoryDAL()) { category = _mapper.Map <List <CategoryDTO> >(entities.tblCategories).ToList(); } return(category); }
public List <FeedBackDTO> GetFeedBacks() { List <FeedBackDTO> FedBack = new List <FeedBackDTO>(); using (var entities = new CategoryDAL()) { FedBack = _mapper.Map <List <FeedBackDTO> >(entities.tblFeedbacks).ToList(); } return(FedBack); }
public static List <Product> GetByCategory(int categoryId) { List <Product> products = new List <Product>(); try { using (SqlConnection con = new SqlConnection(conString)) { if (con.State == ConnectionState.Closed) { con.Open(); } string query = "SELECT * FROM Products WHERE CategoryId=@categoryId"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.Add(new SqlParameter("@categoryId", categoryId)); SqlDataReader reader = cmd.ExecuteReader(); if (reader != null) { if (reader.HasRows) { while (reader.Read()) { Product product = new Product() { ProductId = int.Parse(reader["ProductId"].ToString()), Title = reader["Title"].ToString(), Brand = reader["Brand"].ToString(), Description = reader["Description"].ToString(), ImageURL = reader["ImageUrl"].ToString(), UnitPrice = float.Parse(reader["UnitPrice"].ToString()), Balance = int.Parse(reader["Balance"].ToString()), CategoryInfo = CategoryDAL.Get(int.Parse(reader["CategoryId"].ToString())) }; products.Add(product); } reader.Close(); } } if (con.State == ConnectionState.Open) { con.Close(); } } } catch (Exception ex) { throw ex; } return(products); }
private static Product extractData(SQLiteDataReader reader) { Product product = new Product(); product.Id = reader.GetInt32(0); product.Name = reader.GetString(1); product.Description = reader.GetString(2); product.Price = reader.GetDouble(3); product.Amount = reader.GetInt32(4); product.Category = CategoryDAL.GetById(reader.GetInt32(5)); product.Image = reader.GetString(6); return(product); }