Exemplo n.º 1
0
 public string Update(Goods c)
 {
     YogaEntities ey = new YogaEntities();
     Goods cc = ey.Goods.FirstOrDefault((ccc) => ccc.Id == c.Id);
     if (cc == null) return string.Format("编号为{0}的商品不存在", c.Id);
     cc.Price = c.Price;
     cc.Name = c.Name;
     return ey.SaveChanges() == 1 ? "成功" : "失败";
 }
Exemplo n.º 2
0
 public Goods[] Search(Goods c, ref int page, int pageSize, out int totalPages)
 {
     YogaEntities ey = new YogaEntities();
     var query = from cc in ey.Goods where cc.Name.Contains(c.Name) select cc;
     if (c.Id > 0) query = query.Where((cc) => cc.Id == c.Id);
     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();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Goods EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToGoods(Goods goods)
 {
     base.AddObject("Goods", goods);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a new Goods object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 public static Goods CreateGoods(global::System.Int32 id, global::System.String name, global::System.Double price)
 {
     Goods goods = new Goods();
     goods.Id = id;
     goods.Name = name;
     goods.Price = price;
     return goods;
 }
Exemplo n.º 5
0
 public int Add(Goods a)
 {
     YogaEntities ey = new YogaEntities();
     ey.AddToGoods(a);
     return ey.SaveChanges() == 1 ? a.Id:-1;
 }