public static response GetProductWCP(string token, string clientKey) { try { Class_Product _prod = new Class_Product(); DataClassesDataContext db = new DataClassesDataContext(); var clientToken = db.TBConfigurations.Where(x => x.Name.Contains("WCP_Token")).FirstOrDefault(); if (clientKey != ConfigurationManager.AppSettings["Key"]) { return(new response("failed", "Invalid client key", null)); } if (token != clientToken.Value) { return(new response("failed", "Invalid client token", null)); } dynamic product = _prod.Dynamic_GetAll(db);; return(new response("success", "Product fetched succesfully", product)); } catch (Exception ex) { return(new response("error", ex.Message, null)); } }
public IEnumerable <dynamic> Dynamic_GetAll(DataClassesDataContext db) { try { Class_Product _product = new Class_Product(); return(Dynamic_Func_GetAll(db).AsEnumerable().Select(x => new { x.IDCategory, x.IDCategoryParent, ParentName = x.ParentName, Image = OurClass.ImageExists(x.Image, "category") ? x.Image : "noimage.jpg", x.Name, x.Description, x.Active, Child = Dynamic_GetDataBy_IDCategoryParent(db, x.IDCategory), TotalProduct = _product.AJAX_FE_GetTotalProduct_ByIDCategory(x.IDCategory) }).ToArray()); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(null); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { Class_Product _product = new Class_Product(); foreach (string s in HttpContext.Current.Request.Files) { _product.AJAX_Insert_Photo(WITLibrary.ConvertString.ToInt(Request.QueryString["id"].ToString()), Request.Files[s]); } } }
public IEnumerable <dynamic> Dynamic_GetDataBy_IDMenuParent(DataClassesDataContext db, int idMenuParent) { try { Class_Product _product = new Class_Product(); if (idMenuParent == 0) { return(db.TBMenus.Where(x => x.IDMenuParent == idMenuParent).AsEnumerable().Select(x => new { x.IDMenu, x.IDMenuParent, x.Name, x.Link, AttributeValue = x.Name.Replace(" ", "_").ToLower(), x.DateInsert, x.DateLastUpdate }).ToArray()); } return(db.TBMenus.Where(x => x.IDMenuParent == idMenuParent).AsEnumerable().Select(x => new { x.IDMenu, x.IDMenuParent, x.Name, x.Link, AttributeValue = x.Name.Replace(" ", "_").ToLower(), x.DateInsert, x.DateLastUpdate }).ToArray()); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(null); } }
protected void btnExportProduct_Click(object sender, EventArgs e) { DataClassesDataContext db = new DataClassesDataContext(); Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Product_" + DateTime.Now.ToShortDateString() + ".xls")); Response.ContentType = "application/ms-excel"; Class_Product _product = new Class_Product(); var data = db.TBProducts; string category = ""; DataTable dt = new DataTable(); dt.Columns.Add("ProductCode", typeof(string)); dt.Columns.Add("CombinationCode", typeof(string)); dt.Columns.Add("Manufacturer", typeof(string)); dt.Columns.Add("Categories", typeof(string)); dt.Columns.Add("ProductName", typeof(string)); dt.Columns.Add("Size", typeof(string)); dt.Columns.Add("Color", typeof(string)); dt.Columns.Add("Hexacolor", typeof(string)); dt.Columns.Add("Price", typeof(string)); dt.Columns.Add("Weight", typeof(string)); dt.Columns.Add("Quantity", typeof(string)); dt.Columns.Add("Description", typeof(string)); dt.Columns.Add("ShortDescription", typeof(string)); dt.Columns.Add("Active", typeof(string)); foreach (var item in data) { foreach (var categories in item.TBProduct_Categories) { category += categories.TBCategory.Name + ", "; } foreach (var combination in item.TBProduct_Combinations) { //string[] comname = combination.Name.Split(new[] { ',' }, 2); dt.Rows.Add(item.ReferenceCode, combination.ReferenceCode, item.TBManufacturer.Name, category, item.Name, combination.Name.ToLower().Replace("size : ", ""), "-", "-", item.Price, item.Weight, combination.Quantity, "-", "-", item.Active); } } string str = string.Empty; foreach (DataColumn dtcol in dt.Columns) { Response.Write(dtcol.ColumnName); Response.Write("\t"); } Response.Write("\n"); foreach (DataRow dr in dt.Rows) { str = ""; for (int i = 0; i < dt.Columns.Count; i++) { Response.Write(Convert.ToString(dr[i])); Response.Write("\t"); } Response.Write("\n"); } Response.End(); }