//המרת קטגוריה בודדת מסוג המסד לסוג המחלקה public static categoryEntity ConvertDBToEntity(categoryTBL c) { return(new categoryEntity() { id = c.id, name = c.name }); }
//פונקציה לעדכון קטגוריה public static List <categoryEntity> EditCategory(categoryEntity c) { try { categoryTBL categoryForUpdate = connectDB.entity.categoryTBL.FirstOrDefault(x => x.id == c.id); categoryForUpdate.name = c.name; connectDB.entity.SaveChanges(); } catch { } return(categoryEntity.ConvertListDBToListEntity(connectDB.entity.categoryTBL.ToList())); }
//פונקציה להסרת קטגוריה מהרשימה public static List <categoryEntity> DeleteFromList(int id) { try { categoryTBL categoryForDeleting = connectDB.entity.categoryTBL.FirstOrDefault(x => x.id == id); if (categoryForDeleting.clothesTBL.Count() == 0)//מחיקה רק אם לקטגוריה אין בגדים משויכים { connectDB.entity.categoryTBL.Remove(categoryForDeleting); connectDB.entity.SaveChanges(); } } catch { } return(categoryEntity.ConvertListDBToListEntity(connectDB.entity.categoryTBL.ToList())); }