/// <summary> /// Insert Product Type Information /// </summary> /// <param name="data">Product Type Information</param> /// <returns>Number Affected Row</returns> public static Tuple <ErrorObject, string> ProductType(tblProductType data) { erros = new ErrorObject(); try { using (HSCMEntities db = new HSCMEntities()) { int propertyFind = db.tblProductType.Count(); if (propertyFind > 0) { data.id = db.tblCellarArea.Max(s => s.id); } else { data.id = 1; } db.tblProductType.Add(data); result = db.SaveChanges(); Message = "Affected Row: " + result.ToString(); return(new Tuple <ErrorObject, string>(erros.IfError(false), Message)); } } catch (Exception ex) { erros.InfoError(ex); return(new Tuple <ErrorObject, string>(erros, String.Empty)); } }
protected void btnSubmit_Click(object sender, EventArgs e) { ProductTypeModel model = new ProductTypeModel(); tblProductType pt = CreateProductType(); lblResult.Text = model.InsertProduct(pt); }
/// <summary> /// Return Affected Row Or Error If Exist /// </summary> /// <param name="request">ProductType Information</param> /// <returns>Affected Row Or Error If Exist</returns> public static GetProductTypeResponse ProductType(GetProductTypeResponse request) { GetProductTypeResponse response = new GetProductTypeResponse(); try { tblProductType ProductType = new tblProductType() { id = request.ProductType.id, name = request.ProductType.name, detail = request.ProductType.detail, createDate = request.ProductType.createDate, upDateDate = DateTime.Now, deleteDate = null, state = "Active" }; var result = ProductTypeData.Update.ProductType(ProductType); if (result.Item1.Error) { response.Error.InfoError(result.Item1); } else { response.Message = result.Item2; } } catch (Exception ex) { response.Error.InfoError(ex); } return(response); }
private tblProductType CreateProductType() { tblProductType p = new tblProductType(); p.Name = txtName.Text; return(p); }
public string InsertProduct(tblProductType productType) { try { OnlineKitchenDBEntities db = new OnlineKitchenDBEntities(); db.tblProductTypes.Add(productType); db.SaveChanges(); return(productType.Name + " was successfully inserted"); } catch (Exception e) { return("Error: " + e); } }
public string DeleteProduct(int id) { try { OnlineKitchenDBEntities db = new OnlineKitchenDBEntities(); tblProductType productType = db.tblProductTypes.Find(id); db.tblProductTypes.Attach(productType); db.tblProductTypes.Remove(productType); db.SaveChanges(); return(productType.Name + " was successfully deleted"); } catch (Exception e) { return("Error: " + e); } }
/// <summary> /// Update Cellar Area Information /// </summary> /// <param name="data">Cellar Area Information</param> /// <returns>Number Affected Row</returns> public static Tuple <ErrorObject, string> ProductType(tblProductType data) { erros = new ErrorObject(); try { using (HSCMEntities db = new HSCMEntities()) { db.Entry(data).State = EntityState.Modified; result = db.SaveChanges(); Message = "Affected Row: " + result.ToString(); return(new Tuple <ErrorObject, string>(erros.IfError(false), Message)); } } catch (Exception ex) { erros.InfoError(ex); return(new Tuple <ErrorObject, string>(erros, String.Empty)); } }
public string UpdateProduct(int id, tblProductType productType) { try { OnlineKitchenDBEntities db = new OnlineKitchenDBEntities(); //Fetch object from db tblProductType p = db.tblProductTypes.Find(id); p.Name = productType.Name; db.SaveChanges(); return(productType.Name + " was successfully updated"); } catch (Exception e) { return("Error: " + e); } }
/// <summary> /// Return Product Type By Specific ID /// </summary> /// <param name="id">Product Type ID</param> /// <returns>Produc Type By Specific ID Or null If Exist Error</returns> public static Tuple <ErrorObject, tblProductType> GetProductType(int id) { tblProductType productType = new tblProductType(); erros = new ErrorObject(); try { using (HSCMEntities db = new HSCMEntities()) { productType = db.tblProductType.Find(id); } erros.Error = false; return(new Tuple <ErrorObject, tblProductType>(erros.IfError(false), productType)); } catch (Exception ex) { erros.InfoError(ex); return(new Tuple <ErrorObject, tblProductType>(erros, productType)); } }
/// <summary> /// Update Cellar Area Information /// </summary> /// <param name="data">Cellar Area Information</param> /// <returns>Number Affected Row</returns> public static Tuple <ErrorObject, string> ProductType(tblProductType data) { erros = new ErrorObject(); try { using (EileenGaldamezEntities db = new EileenGaldamezEntities()) { var row = db.tblProductType.Single(p => p.id == data.id); row.name = data.name; row.detail = data.detail; row.upDateDate = data.upDateDate; result = db.SaveChanges(); Message = "Affected Row: " + result.ToString(); return(new Tuple <ErrorObject, string>(erros.IfError(false), Message)); } } catch (Exception ex) { erros.InfoError(ex); return(new Tuple <ErrorObject, string>(erros, String.Empty)); } }