/// <summary> /// 删除小区价格趋势 /// </summary> /// <param name="neighborhood">小区</param> public HttpResponseMessage Delete(string neighborhood) { if (string.IsNullOrEmpty(neighborhood)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } else { var entity = new NeighborhoodPriceTrend() { Neighborhood = neighborhood }; NeighborhoodPriceTrendFunction neighborhoodPriceTrendFunction = new NeighborhoodPriceTrendFunction(); int error = neighborhoodPriceTrendFunction.DeleteNeighborhoodPriceTrend(entity); var response = GetResponse.PriceTrendResponse(error); return response; } }
//新增小区价格趋势 public int AddNeighborhoodPriceTrend(NeighborhoodPriceTrend entity) { using (var db = new HouseMarketEntities()) { if (db.NeighborhoodPriceTrends.Any(c => c.Neighborhood == entity.Neighborhood && c.Date == entity.Date)) { return (int)Errors.PriceTrendErrors.RecordExisted; } else if (entity.ID != 0 || entity.Neighborhood == null || entity.NeighborhoodAvgPrice == null || entity.Date == null) { return (int)Errors.PriceTrendErrors.WrongParameter; } else { db.NeighborhoodPriceTrends.Add(entity); db.SaveChanges(); return 0; } } }
//删除小区价格趋势 public int DeleteNeighborhoodPriceTrend(NeighborhoodPriceTrend entity) { using (var db = new HouseMarketEntities()) { if (entity.ID == 0) { return (int)Errors.PriceTrendErrors.NullParameter; } else { var neighborhoodPriceTrend = db.NeighborhoodPriceTrends.FirstOrDefault(c => c.ID == entity.ID); if (neighborhoodPriceTrend == null) { return (int)Errors.PriceTrendErrors.PriceTrendIDNotExisted; } else { db.NeighborhoodPriceTrends.Remove(neighborhoodPriceTrend); db.SaveChanges(); return 0; } } } }
//编辑小区价格趋势 public int EditNeighborhoodPriceTrend(NeighborhoodPriceTrend entity) { using (var db = new HouseMarketEntities()) { if (db.NeighborhoodPriceTrends.Any(c => c.Neighborhood == entity.Neighborhood && c.Date == entity.Date)) { return (int)Errors.PriceTrendErrors.RecordExisted; } else if (entity.ID == 0) { return (int)Errors.PriceTrendErrors.NullParameter; } else if (entity.Neighborhood == null || entity.NeighborhoodAvgPrice == null || entity.Date == null) { return (int)Errors.PriceTrendErrors.WrongParameter; } else { var neighborhoodPriceTrend = db.NeighborhoodPriceTrends.FirstOrDefault(c => c.ID == entity.ID); if (neighborhoodPriceTrend == null) { return (int)Errors.PriceTrendErrors.PriceTrendIDNotExisted; } else { PropertyFunction.CopyEntity(entity, neighborhoodPriceTrend); db.SaveChanges(); return 0; } } } }