/// <summary> /// 删除地区价格趋势 /// </summary> /// <param name="area">地区</param> public HttpResponseMessage Delete(string area) { if (string.IsNullOrEmpty(area)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } else { var entity = new AreaPriceTrend() { Area = area }; AreaPriceTrendFunction areaPriceTrendFunction = new AreaPriceTrendFunction(); int error = areaPriceTrendFunction.DeleteAreaPriceTrend(entity); var response = GetResponse.PriceTrendResponse(error); return response; } }
//新增地区价格趋势 public int AddAreaPriceTrend(AreaPriceTrend entity) { using (var db = new HouseMarketEntities()) { if (db.AreaPriceTrends.Any(c => c.Area == entity.Area && c.Date == entity.Date)) { return (int)Errors.PriceTrendErrors.RecordExisted; } else if (entity.ID != 0 || entity.Area == null || entity.AreaAvgPrice == null || entity.Date == null) { return (int)Errors.PriceTrendErrors.WrongParameter; } else { db.AreaPriceTrends.Add(entity); db.SaveChanges(); return 0; } } }
//删除地区价格趋势 public int DeleteAreaPriceTrend(AreaPriceTrend entity) { using (var db = new HouseMarketEntities()) { if (entity.ID == 0) { return (int)Errors.PriceTrendErrors.NullParameter; } else { var areaPriceTrend = db.AreaPriceTrends.FirstOrDefault(c => c.ID == entity.ID); if (areaPriceTrend == null) { return (int)Errors.PriceTrendErrors.PriceTrendIDNotExisted; } else { db.AreaPriceTrends.Remove(areaPriceTrend); db.SaveChanges(); return 0; } } } }
//编辑地区价格趋势 public int EditAreaPriceTrend(AreaPriceTrend entity) { using (var db = new HouseMarketEntities()) { if (db.AreaPriceTrends.Any(c => c.Area == entity.Area && c.Date == entity.Date)) { return (int)Errors.PriceTrendErrors.RecordExisted; } else if (entity.ID == 0) { return (int)Errors.PriceTrendErrors.NullParameter; } else if (entity.Area == null || entity.AreaAvgPrice == null || entity.Date == null) { return (int)Errors.PriceTrendErrors.WrongParameter; } else { var areaPriceTrend = db.AreaPriceTrends.FirstOrDefault(c => c.ID == entity.ID); if (areaPriceTrend == null) { return (int)Errors.PriceTrendErrors.PriceTrendIDNotExisted; } else { PropertyFunction.CopyEntity(entity, areaPriceTrend); db.SaveChanges(); return 0; } } } }