//编辑收藏 public int EditCollection(Collection entity) { using (var db = new HouseMarketEntities()) { if (db.Collections.Any(c => c.CustomerID == entity.CustomerID && c.HouseID == entity.HouseID)) { return (int)Errors.CollectionErrors.RecordExisted; } else if (entity.CollectionID == 0) { return (int)Errors.CollectionErrors.NullParameter; } else if (entity.HouseID == 0 || entity.CustomerID == 0) { return (int)Errors.CollectionErrors.WrongParameter; } else { var collection = db.Collections.FirstOrDefault(c => c.CollectionID == entity.CollectionID); if (collection == null) { return (int)Errors.CollectionErrors.CollectionIDNotExisted; } else { PropertyFunction.CopyEntity(entity, collection); db.SaveChanges(); return 0; } } } }
/// <summary> /// 删除收藏 /// </summary> /// <param name="collectionID">收藏编号</param> public HttpResponseMessage Delete(int collectionID) { if (collectionID == 0) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } else { var entity = new Collection() { CollectionID = collectionID }; CollectionFunction collectionFunction = new CollectionFunction(); int error = collectionFunction.DeleteCollection(entity); var response = GetResponse.CollectionResponse(error); return response; } }
//新增收藏 public int AddCollection(Collection entity) { using (var db = new HouseMarketEntities()) { if (db.Collections.Any(c => c.CustomerID == entity.CustomerID && c.HouseID == entity.HouseID)) { return (int)Errors.CollectionErrors.RecordExisted; } else if (entity.HouseID == null || entity.CustomerID == null || entity.HouseID == 0 || entity.CustomerID == 0) { return (int)Errors.CollectionErrors.WrongParameter; } else { db.Collections.Add(entity); db.SaveChanges(); return 0; } } }
//删除收藏 public int DeleteCollection(Collection entity) { using (var db = new HouseMarketEntities()) { if (entity.CollectionID == 0) { return (int)Errors.CollectionErrors.NullParameter; } else { var collection = db.Collections.FirstOrDefault(c => c.CollectionID == entity.CollectionID); if (collection == null) { return (int)Errors.CollectionErrors.CollectionIDNotExisted; } else { db.Collections.Remove(collection); db.SaveChanges(); return 0; } } } }