private void detach_Volumes(Volume entity) { this.SendPropertyChanging(); entity.Computers = null; }
private void attach_Volumes(Volume entity) { this.SendPropertyChanging(); entity.Computers = this; }
partial void DeleteVolume(Volume instance);
partial void UpdateVolume(Volume instance);
partial void InsertVolume(Volume instance);
public ActionResult Volumes(string method, string id) { string token = Request["token"]; string userid = APITokens.GetUserID(token); if (method == "get") { return new JSONResponseResult("ok"); } else if (method == "list") { int computerid = 0; if (!string.IsNullOrEmpty(Request["token"])) int.TryParse(Request["token"], out computerid); JSONWriter jw = new JSONWriter(); jw.Class(); jw.Array("volumes"); DBDataContext db = new DBDataContext(); var vols = from v in db.Volumes select v; if (computerid != 0) vols = from v in vols where v.ComputerID.Equals(computerid) select v; foreach (Volume v in vols) { jw.Class(); jw.Field("id", v.ID); jw.Field("name", v.VolumeName); if (v.Computers != null) { jw.Field("computerid", v.Computers.ID); jw.Field("computername", v.Computers.ComputerName); } jw.End(); } jw.End(); jw.End(); return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty)); } else if (method == "add") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); int compid = 0; int.TryParse(Request["computer"], out compid); int ds = 0; int.TryParse(Request["disksize"], out ds); int du = 0; int.TryParse(Request["diskused"], out du); DBDataContext db = new DBDataContext(); Volume v = new Volume(); v.ComputerID = compid; v.CreatedDate = DateTime.Now; db.Volumes.InsertOnSubmit(v); db.SubmitChanges(); return new JSONResponseResult("{ status:'ok', id:'" + v.ID + "' }"); } else if (method == "remove") { if (string.IsNullOrEmpty(userid)) return new JSONResponseResult("not authenticated"); } return new JSONResponseResult("unknown volumes-command; method=" + method + ", id=" + id); }