public static OrganizationType FetchOrCreateType(CMSDataContext Db, string type) { var t = Db.OrganizationTypes.SingleOrDefault(pp => pp.Description == type); if (t == null) { var max = 10; if (Db.OrganizationTypes.Any()) { max = Db.OrganizationTypes.Max(mm => mm.Id) + 10; } t = new OrganizationType { Description = type, Code = type.Substring(0, 3), Id = max }; Db.OrganizationTypes.InsertOnSubmit(t); Db.SubmitChanges(); } return(t); }
public static OrganizationType FetchOrCreateType(CMSDataContext Db, string type) { var t = Db.OrganizationTypes.SingleOrDefault(pp => pp.Description == type); if (t == null) { var max = 10; if (Db.OrganizationTypes.Any()) max = Db.OrganizationTypes.Max(mm => mm.Id) + 10; t = new OrganizationType { Description = type, Code = type.Substring(0, 3), Id = max }; Db.OrganizationTypes.InsertOnSubmit(t); Db.SubmitChanges(); } return t; }