Ejemplo n.º 1
0
        public CategorySearchResponse GetCategories()
        {
            List<Category> categories = new List<Category>();
            productDataManager = new ProductDataManager();
            DataSet ds = productDataManager.GetCategories();
            CategorySearchResponse response = new CategorySearchResponse();
            DataTable dtCategory=new DataTable();
            dtCategory = ds.Tables[0];
            if (dtCategory.Rows.Count > 0)
            {
                foreach (DataRow dr in dtCategory.Rows)
                {
                    Category category = new Category();
                    category.CategoryId = Convert.ToInt32(dr["CategoryId"]);
                    category.CategoryName = dr["CategoryName"].ToString();
                    categories.Add(category);
                }
            }

            response.CategoryList = categories;

            return response;
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["product"] != null)
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Product product = serializer.Deserialize<Product>(Request.Params["product"]);//convert json string into .net objects
                if (Request.Params["CategoryId"] != null)
                {
                    product.Category.CategoryId = Convert.ToInt32(Request.Params["CategoryId"]);
                }

                if (Request.Params["action"] != null && Request.Params["action"] == "save")
                {

                    SaveProduct(product);
                }

            }
            //Not using Web Method
            //if (Request.Params["action"] != null && Request.Params["action"] == "get")
            //{
            //    //GetProducts();
            //    BindDataTable(PageIndex);

            //}
            if (Request.Params["product"] != null)
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Product product = serializer.Deserialize<Product>(Request.Params["product"]);
                try
                {
                    if (Request.Params["CategoryId"] != null)
                    {
                        product.Category.CategoryId = Convert.ToInt32(Request.Params["CategoryId"]);
                    }
                }
                catch (InvalidCastException ex)
                {

                    throw new InvalidCastException("Category cannot be null", ex);

                }
                if (Request.Params["action"] != null && Request.Params["action"] == "update")
                {

                    UpdateProducts(product);
                }
            }
            if (Request.Params["Id"] != null)
            {

                if (Request.Params["action"] != null && Request.Params["action"] == "delete")
                {

                    int Id = Convert.ToInt32(Request.Params["Id"]);
                    DeleteProducts(Id);

                }
            }

            foreach(string file in Request.Files)
            {
                Category category = new Category();

                    if (Request.Form["txtCategoryName"] != "")
                    {
                        category.CategoryName = Convert.ToString(Request.Form["txtCategoryName"]);
                    }

                if (Request.Form["ValueHiddenField"] != null)
                {
                    string Category = Request.Form["ValueHiddenField"];
                    category.ParentId = Convert.ToInt32(Category);
                }

                if (Request.Files[file] != null)
                {
                    HttpPostedFile postedfile = Request.Files[file];
                    string fileName = Path.GetFileName(postedfile.FileName);
                    string path = Path.Combine(Server.MapPath(System.Web.Configuration.WebConfigurationManager.AppSettings["filepath"].ToString()), fileName);
                    //string filetype = postedfile.ContentType;
                    //int fileSize = postedfile.ContentLength;
                    //if (filetype != "image/gif" && filetype != "image/jpeg" && filetype != "image/png")
                    //{
                    //    System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Can upload only images')</SCRIPT>");

                    //}
                    //else
                    //{
                    //    if (fileSize > 2097152)
                    //    {
                    //        System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Upload file less than 2mb')</SCRIPT>");

                    //    }
                    //    else
                    //    {
                    postedfile.SaveAs(path);
                    category.ImageName = fileName;
                }
                        IProductManager productManager = ProductFactory.GetProductManager();

                        int result = productManager.InsertCategory(category);
                       // Response.Clear();

                        if (result > 0)
                        {
                            //Response.Write("Successfully Inserted");
                            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alertMessage", "alert('Record Inserted Successfully');", true);

                        }
                        else
                        {
                            Response.Write("Error while inserting data");
                        }
                        //Response.End();

                   // }
               // }
            }
        }
Ejemplo n.º 3
0
 public int InsertCategory(Category category)
 {
     productDataManager = new ProductDataManager();
     return productDataManager.InsertCategory(category.CategoryName,category.ImageName,category.ParentId);
 }
 public int InsertCategory(Category category)
 {
     throw new NotImplementedException();
 }