public string Update(Rack c, DateTime start, DateTime end) { YogaEntities ey = new YogaEntities(); Rack cc = ey.Rack.FirstOrDefault((ccc) => ccc.Id == c.Id); if (cc == null) return string.Format("编号为{0}的柜子不存在", c.Id); cc.RackNo = c.RackNo; cc.RentDate = start; cc.RentExpire = end; cc.RenterId = c.RenterId>0?c.RenterId:null; cc.Remarks = c.Remarks; return ey.SaveChanges() == 1 ? "成功" : "失败"; }
public Rack[] Search(Rack c, ref int page, int pageSize, out int totalPages) { YogaEntities ey = new YogaEntities(); var query = from cc in ey.Rack where cc.RackNo.Contains(c.RackNo) select cc; //if (c.Id > 0) query = query.Where((cc) => cc.Id == c.Id); if (c.RenterId > 0) query = query.Where((cc) => cc.RenterId == c.RenterId); totalPages = (int)Math.Ceiling(query.Count() * 1.0 / pageSize); if (totalPages < 1) { page = 0; return null; } if (page == -1 || page > totalPages) page = totalPages; else if (page < 1) page = 1; return query.OrderBy((cc) => cc.Id).Skip((page - 1) * pageSize).Take(pageSize).ToArray(); }
/// <summary> /// Deprecated Method for adding a new object to the Rack EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToRack(Rack rack) { base.AddObject("Rack", rack); }
/// <summary> /// Create a new Rack object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="rentDate">Initial value of the RentDate property.</param> /// <param name="rentExpire">Initial value of the RentExpire property.</param> public static Rack CreateRack(global::System.Int32 id, global::System.DateTime rentDate, global::System.DateTime rentExpire) { Rack rack = new Rack(); rack.Id = id; rack.RentDate = rentDate; rack.RentExpire = rentExpire; return rack; }
public int Add(Rack a) { YogaEntities ey = new YogaEntities(); ey.AddToRack(a); return ey.SaveChanges() == 1 ? a.Id : -1; }