/// <summary> /// 增加刮刮卡 /// </summary> /// <param name="model"></param> /// <returns></returns> public string Update_DinnerCategory(DinnerCategory model, string unid) { if (model == null || !model.Name.IsNotNullOrEmpty() ) { return("数据为空"); } using (DbRepository entities = new DbRepository()) { var oldEntity = entities.DinnerCategory.Find(unid); if (oldEntity != null) { var query = entities.DinnerCategory.AsQueryable(); if (query.Where(x => x.Name.Equals(model.Name) && !x.UNID.Equals(unid) && x.ShopId.Equals(oldEntity.UNID)).Count() != 0) { return("分类名称已存在"); } oldEntity.Sort = model.Sort; oldEntity.Name = model.Name; oldEntity.UpdatedTime = DateTime.Now; } else { return("数据为空"); } return(entities.SaveChanges() > 0 ? "" : "保存出错"); } }
/// <summary> /// 增加刮刮卡 /// </summary> /// <param name="model"></param> /// <returns></returns> public string Add_DinnerCategory(DinnerCategory model) { if (model == null || !model.Name.IsNotNullOrEmpty() ) { return("数据为空"); } using (DbRepository entities = new DbRepository()) { var query = entities.DinnerCategory.AsQueryable(); var shop = entities.DinnerShop.Find(model.ShopId); if (shop == null) { return("店铺不存在"); } if (query.Where(x => x.Name.Equals(model.Name) && x.ShopId.Equals(shop.UNID)).Count() != 0) { return("分类名称已存在"); } var addEntity = new DinnerCategory(); addEntity.UNID = Guid.NewGuid().ToString("N"); addEntity.Sort = model.Sort; addEntity.Name = model.Name; addEntity.CreatedTime = DateTime.Now; addEntity.UpdatedTime = DateTime.Now; addEntity.ShopId = shop.UNID; entities.DinnerCategory.Add(addEntity); return(entities.SaveChanges() > 0 ? "" : "保存出错"); } }