/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public static SchoolPO GetDataForSave(int id) { SchoolPO item; if (id == 0) { item = new SchoolPO() { Name = "", Shortname = "", Branchname = "", Logo = "", Introduction = "", DistrictId = 0, Address = "", Longitude = 0, Latitude = 0, Status = 0, Createtime = DateTime.Now, Updatetime = DateTime.Now, }; } else { item = GetItem(id); } return(item); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public static bool Delete(int id) { var item = new SchoolPO { Id = id }; return(Delete(item)); }
/// <summary> /// /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool Delete(SchoolPO item) { using (var context = new SchoolContext()) { context.Schools.Attach(item); context.Schools.Remove(item); context.SaveChanges(); } return(true); }
/// <summary> /// /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool Save(SchoolPO item) { using (var context = new SchoolContext()) { if (item.Id == 0) { context.Schools.Add(item); } else { context.Entry(item).State = EntityState.Modified; } context.SaveChanges(); } return(true); }
public static SchoolModel ToModel(this SchoolPO item) { if (item == null) { return(null); } return(new SchoolModel { Id = item.Id, Name = item.Name, Shortname = item.Shortname, Branchname = item.Branchname, Logo = item.Logo, Introduction = item.Introduction, DistrictId = item.DistrictId, Address = item.Address, Longitude = item.Longitude, Latitude = item.Latitude, Status = item.Status, Createtime = item.Createtime, Updatetime = item.Updatetime, }); }