public static int AddCategory(CategoryGMH c) { using (DAL.Charity_DBEntities db = new DAL.Charity_DBEntities()) { if (c.MasterCategoryCode == 0) { c.MasterCategoryCode = null; } db.CategoryGMH.Add(BL.Converters.CategoryGMHConvereter.ConvertToDAL(c)); try { db.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var entityValidationErrors in ex.EntityValidationErrors) { foreach (var validationError in entityValidationErrors.ValidationErrors) { System.Diagnostics.Debug.WriteLine( "Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage); } } System.Diagnostics.Debug.WriteLine("no"); } db.CategoryGMH.ToArray().Last().MasterCategoryCode = null; return(db.CategoryGMH.ToArray().Last().CategoryCode); } }
public static CategoryGMH[] getCategoriesForGmach(CategoryGMH masterGmachCode) { using (DAL.Charity_DBEntities db = new DAL.Charity_DBEntities()) { List <CategoryGMH> a = BL.Converters.CategoryGMHConvereter.convertToDTOList(db.CategoryGMH.Where(s => s.MasterCategoryCode == masterGmachCode.CategoryCode).ToList()); return(a.ToArray <CategoryGMH>()); } }