public int UpdateSubCategory(int input) { System.Console.Write("Sub Category Name : "); string subcatname = System.Console.ReadLine(); System.Console.Write("Category ID : "); int catid = Convert.ToInt32(System.Console.ReadLine()); Console.WriteLine("\n"); Console.WriteLine("============================================="); System.Console.Write("MASUKKAN ULANG ID : "); int id_subcat = Convert.ToInt32(System.Console.ReadLine()); var getmhs = hld_context.SubCategory_s.Find(id_subcat); if (getmhs == null) { System.Console.Write("TIDAK ADA ID SUBCATEGORY : " + id_subcat); } else { SubCategoryCls ct = GetByid(input); ct.ID = id_subcat; // ct.CategoryID = catid; ct.SubCategory_Name = subcatname; hld_context.Entry(ct).State = System.Data.Entity.EntityState.Modified; hld_context.SaveChanges(); } return(input); }
// =========================================== INSERT ============================================= public void InsertSubCategory() { Console.Clear(); System.Console.Write("SubCategory Name : "); string catname = System.Console.ReadLine(); System.Console.Write("Category ID : "); int catid = Convert.ToInt32(System.Console.ReadLine()); SubCategoryCls call = new SubCategoryCls(); { call.SubCategory_Name = catname; //call.CategoryID = catid; }; try { hld_context.SubCategory_s.Add(call); var result = hld_context.SaveChanges(); } catch (Exception ex) { System.Console.Write(ex.InnerException); } }