public Dictionary <string, object> Modify([FromBody] HandHouse handHouse) { HandHouse newHandHouse = db.HandHouses.FirstOrDefault(w => w.HandId == handHouse.HandId); if (db.Properties.Count(w => w.OwnerId == newHandHouse.OwnerId) > 0) { result["code"] = "failed"; message.Add("已缴纳物业费,无法修改"); } else if (db.WaterAndElectricities.Count(w => w.OwnerId == newHandHouse.OwnerId) > 0) { result["code"] = "failed"; message.Add("已缴纳水电费,无法修改"); } else if (db.ElseCosts.Count(w => w.OwnerId == newHandHouse.OwnerId) > 0) { result["code"] = "failed"; message.Add("已缴纳费用,无法修改"); } else { newHandHouse.HandDate = handHouse.HandDate; newHandHouse.PropertyStartDate = handHouse.PropertyStartDate; newHandHouse.Remark = handHouse.Remark; Owner owner = db.Owners.FirstOrDefault(w => w.OwnerId == handHouse.OwnerId); owner.HandDate = handHouse.HandDate; owner.PropertyStartDate = handHouse.PropertyStartDate; owner.PropertyExpireDate = owner.PropertyStartDate; House house = db.Houses.FirstOrDefault(w => w.HouseId == owner.HouseId); house.HandDate = handHouse.HandDate; db.SaveChanges(); } result["message"] = message; return(result); }
public Dictionary <string, object> Delete(int id) { HandHouse handHouse = db.HandHouses.FirstOrDefault(w => w.HandId == id); if (db.Properties.Count(w => w.OwnerId == handHouse.OwnerId) > 0) { result["code"] = "failed"; message.Add("已缴纳物业费,无法删除"); } else if (db.WaterAndElectricities.Count(w => w.OwnerId == handHouse.OwnerId) > 0) { result["code"] = "failed"; message.Add("已缴纳水电费,无法删除"); } else if (db.ElseCosts.Count(w => w.OwnerId == handHouse.OwnerId) > 0) { result["code"] = "failed"; message.Add("已缴纳费用,无法删除"); } else { Owner owner = db.Owners.FirstOrDefault(w => w.OwnerId == handHouse.OwnerId); owner.HandDate = null; owner.PropertyStartDate = null; House house = db.Houses.FirstOrDefault(w => w.HouseId == owner.HouseId); house.HandDate = null; db.HandHouses.Remove(handHouse); db.SaveChanges(); } result["message"] = message; return(result); }
public Dictionary <string, object> Add([FromBody] HandHouse handHouse) { if (handHouse.OwnerId == 0) { result["code"] = "failed"; message.Add("必须选择一个业主"); } else { handHouse.UserId = user.UserId; handHouse.CreateTime = Ricky.Common.NowDate; Owner owner = db.Owners.FirstOrDefault(w => w.OwnerId == handHouse.OwnerId); owner.HandDate = handHouse.HandDate; owner.PropertyStartDate = handHouse.PropertyStartDate; owner.PropertyExpireDate = owner.PropertyStartDate; House house = db.Houses.FirstOrDefault(w => w.HouseId == owner.HouseId); house.HandDate = handHouse.HandDate; db.HandHouses.Add(handHouse); db.SaveChanges(); } result["message"] = message; return(result); }