Ejemplo n.º 1
0
		private void detach_Volumes(Volume entity)
		{
			this.SendPropertyChanging();
			entity.Computers = null;
		}
Ejemplo n.º 2
0
		private void attach_Volumes(Volume entity)
		{
			this.SendPropertyChanging();
			entity.Computers = this;
		}
Ejemplo n.º 3
0
 partial void DeleteVolume(Volume instance);
Ejemplo n.º 4
0
 partial void UpdateVolume(Volume instance);
Ejemplo n.º 5
0
 partial void InsertVolume(Volume instance);
Ejemplo n.º 6
0
        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);
        }