示例#1
0
        public Response InsertProduct(Models.Product product)
        {
            Response response = null;
            string   Message  = null;
            var      Count    = 0;

            bool status = false;

            if (ModelState.IsValid)
            {
                EntityMapper <Models.Product, DataLayer.Product> mapObj = new EntityMapper <Models.Product, DataLayer.Product>();
                DataLayer.Product productObj = new DataLayer.Product();
                productObj = mapObj.Translate(product);
                status     = DAL.InsertProduct(productObj);
            }

            if (status)
            {
                Message  = Config.INSERT_MESSAGE;
                Count    = 1;
                response = BuildResponse(Config.SUCESS, Count, Message, null, null);
            }
            else
            {
                Message  = Config.INVALID_PARAMETER_MESSAGE;
                response = BuildResponse(Config.FAILED, Count, Message, null, null);
            }
            return(response);
        }
示例#2
0
        static FakeDb()
        {
            var assembly = Assembly.GetExecutingAssembly();
            var stream = assembly.GetManifestResourceStream("DataLayer.words.txt");
            var reader = new StreamReader(stream);
            _words = reader.ReadToEnd().Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 1; i <= 20; i++)
            {
                Category c = new Category();
                c.Id = i;
                c.Name = _words[_rnd.Next(_words.Length)];
                _categories.Add(c);
                for (int j = 1; j <= 20; j++)
                {
                    Product p = new Product();
                    p.Id = j;
                    p.CategoryId = i;
                    p.Name = _words[_rnd.Next(_words.Length)];
                    _products.Add(p);
                }

            }


        }
示例#3
0
        public virtual Response GetProductDetails(Request request)
        {
            Response response = null;
            string   Message  = null;
            var      Count    = 0;

            if (IsValidId(request.Id))
            {
                var Id = request.Id;

                EntityMapper <DataLayer.Product, Models.Product> mapper = new EntityMapper <DataLayer.Product, Models.Product>();
                DataLayer.Product dalProduct = DAL.GetProduct(ToInt(Id));
                Models.Product    product    = new Models.Product();
                product = mapper.Translate(dalProduct);

                if (product != null)
                {
                    Message  = Config.RECORD_FOUND_MESSAGE;
                    Count    = 1;
                    response = BuildResponse(Config.SUCESS, Count, Message, product, null);
                }
                else
                {
                    Message  = Config.RECORD_FOUND_MESSAGE;
                    response = BuildResponse(Config.SUCESS, Count, Message, null, null);
                }
            }
            else
            {
                Message  = Config.INVALID_ID_MESSAGE;
                response = BuildResponse(Config.SUCESS, Count, Message, null, null);
            }
            return(response);
        }
示例#4
0
        public Response UpdateProduct(Models.Product product)
        {
            Response response = null;
            string   Message  = null;
            var      Count    = 0;

            EntityMapper <Models.Product, DataLayer.Product> mapObj = new EntityMapper <Models.Product, DataLayer.Product>();

            DataLayer.Product productObj = new DataLayer.Product();
            productObj = mapObj.Translate(product);
            var status = DAL.UpdateProduct(productObj);

            if (status)
            {
                Message  = Config.UPDATE_MESSAGE;
                Count    = 1;
                response = BuildResponse(Config.SUCESS, Count, Message, null, null);
            }
            else
            {
                Message  = Config.INVALID_PARAMETER_MESSAGE;
                response = BuildResponse(Config.FAILED, Count, Message, null, null);
            }
            return(response);
        }
示例#5
0
 public static ProductModel Map(Product product)
 {
     var model = new ProductModel();
     if (product != null)
     {
         model.ProductId = product.ProductId;
         model.ProductName = product.ProductName;
         model.EanCode = product.EanCode;
         model.ImageUrl = product.ImageUrl;
         model.Price = product.Price;
         model.Length = product.Length;
         model.Width = product.Width;
         model.Height = product.Height;
         model.Cbm = product.Cbm;
         model.Description = product.Description;
     }
     return model;
 }
示例#6
0
        public IEnumerable<Product> GetProductsForCategory(int categoryId)
        {
            List<Product> products = new List<Product>();
            using (var connection = new SqlConnection(_connectionString))
            using (var cmd = connection.CreateCommand())
            {
                cmd.CommandText = "SELECT * FROM Products WHERE CategoryId = @categoryId";
                cmd.Parameters.AddWithValue("@categoryId", categoryId);
                connection.Open();
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Product p = new Product();
                    p.Id = (int) reader["ProductId"];
                    p.Name = (string) reader["ProductName"];
                    p.QuantityPerUnit = (string) reader["QuantityPerUnit"];
                    p.UnitPrice = (decimal) reader["UnitPrice"];
                    products.Add(p);
                }
            }

            return products;
        }
示例#7
0
 public static ProductModel Map(Product product)
 {
     var model = new ProductModel();
     if (product != null)
     {
         model.ProductId = product.ProductId;
         model.ProductName = product.ProductName;
         model.EanCode = product.EanCode;
         model.ImageUrl = product.ImageUrl;
         model.Length = product.Length;
         model.Width = product.Width;
         model.Height = product.Height;
         model.Description = product.Description;
         model.Price = product.Price;
         model.IsOutOfStock = product.IsOutOfStock;
         model.CreationDate = product.CreationDate;
         model.LastModifiedDate = product.LastModifiedDate;
     }
     return model;
 }
示例#8
0
 public static Product Map(ProductModel model)
 {
     var product = new Product();
     if (model != null)
     {
         product.ProductId = model.ProductId;
         product.ProductName = model.ProductName;
         product.EanCode = model.EanCode;
         product.ImageUrl = model.ImageUrl;
         product.Length = model.Length;
         product.Width = model.Width;
         product.Height = model.Height;
         product.Description = model.Description;
         product.Price = model.Price;
         product.IsOutOfStock = model.IsOutOfStock;
         product.CreationDate = model.CreationDate;
         product.LastModifiedDate = model.LastModifiedDate;
     }
     return product;
 }
 /// <summary>
 /// Create a new Product object.
 /// </summary>
 /// <param name="product_id">Initial value of the product_id property.</param>
 public static Product CreateProduct(global::System.Int32 product_id)
 {
     Product product = new Product();
     product.product_id = product_id;
     return product;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Products EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProducts(Product product)
 {
     base.AddObject("Products", product);
 }