Пример #1
0
 private void Dispose(bool disposing)
 {
     if (!disposing || this.resourceModel == null)
     {
         return;
     }
     this.resourceModel.Dispose();
     this.resourceModel = (EditResourceModel)null;
 }
Пример #2
0
        public ActionResult Save(int id, EditResourceModel model)
        {
            var resource = CurrentDatabase.Resources.FirstOrDefault(x => x.ResourceId == id);

            if (model.DivisionId.HasValue && model.DivisionId < 1)
            {
                model.DivisionId = null;
            }

            if (model.CampusId.HasValue && model.CampusId < 1)
            {
                model.CampusId = null;
            }

            resource.Name          = model.Name;
            resource.DisplayOrder  = model.DisplayOrder;
            resource.DivisionId    = model.DivisionId;
            resource.CampusId      = model.CampusId;
            resource.MemberTypeIds = model.MemberTypeIds != null?string.Join(",", model.MemberTypeIds) : string.Empty;

            resource.StatusFlagIds = model.StatusFlagIds != null?string.Join(",", model.StatusFlagIds) : string.Empty;

            resource.Description        = model.Description;
            resource.ResourceTypeId     = model.ResourceTypeId;
            resource.ResourceCategoryId = model.ResourceCategoryId;

            CurrentDatabase.ResourceOrganizations.DeleteAllOnSubmit(
                CurrentDatabase.ResourceOrganizations.Where(ro => ro.ResourceId == resource.ResourceId)
                );
            foreach (var orgId in model.OrganizationIds)
            {
                resource.ResourceOrganizations.Add(new ResourceOrganization
                {
                    Resource       = resource,
                    OrganizationId = orgId
                });
            }

            CurrentDatabase.ResourceOrganizationTypes.DeleteAllOnSubmit(
                CurrentDatabase.ResourceOrganizationTypes.Where(ro => ro.ResourceId == resource.ResourceId)
                );
            foreach (var orgTypeId in model.OrganizationTypeIds)
            {
                resource.ResourceOrganizationTypes.Add(new ResourceOrganizationType
                {
                    Resource           = resource,
                    OrganizationTypeId = orgTypeId
                });
            }

            CurrentDatabase.SubmitChanges();

            return(Redirect("/Resources/" + resource.ResourceId + "/"));
        }
Пример #3
0
 public ResourceEditorControl(DesignerContext designerContext, SceneNodeProperty editingProperty)
 {
     this.designerContext   = designerContext;
     this.editingProperty   = editingProperty;
     this.resourceModel     = this.BuildResourceModelFromPropertyReference();
     this.editingValue      = this.resourceModel.EditorValue;
     this.transactionHelper = new PropertyEditingHelper(this.resourceModel.Document, (UIElement)this);
     this.DataContext       = (object)this;
     this.CommandBindings.Add(new CommandBinding((ICommand)PropertyValueEditorCommands.FinishEditing, new ExecutedRoutedEventHandler(this.OnFinishEditing)));
     PropertyInspectorHelper.SetOwningPropertyInspectorModel((DependencyObject)this, (IPropertyInspector)this);
     PropertyInspectorHelper.SetOwningPropertyInspectorElement((DependencyObject)this, (UIElement)this);
     this.InitializeComponent();
 }
        public Dictionary <string, string> Get(EditResourceModel UpdatedResources)
        {
            UnixCmdHelper _cmd            = new UnixCmdHelper();
            string        consoleresponse = "";
            Dictionary <string, string> responseMessage = new Dictionary <string, string> ();

            try {
                foreach (var rec in UpdatedResources.updatedResourceSettings)
                {
                    switch (rec.Key)
                    {
                    case "CPUs":
                        consoleresponse = _cmd.ExecuteShellCMD("/usr/bin/virsh", "setvcpus " + UpdatedResources.modelID + " " + rec.Value + " --current");
                        break;

                    case "MaxMemory":
                        consoleresponse = _cmd.ExecuteShellCMD("/usr/bin/virsh", "setmem " + UpdatedResources.modelID + " " + rec.Value + " --current");
                        break;

                    case "MinMemory":
                        consoleresponse = _cmd.ExecuteShellCMD("/usr/bin/virsh", "setmemmax " + UpdatedResources.modelID + " " + rec.Value + " --current");
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                    if (!string.IsNullOrEmpty(consoleresponse.Trim()))
                    {
                        throw new Exception(consoleresponse);
                    }
                }
                responseMessage.Add("Result", "Success");
                responseMessage.Add("Message", "Resources Successfully Updated");

                return(responseMessage);
            } catch (Exception error) {
                responseMessage.Clear();
                responseMessage.Add("Result", "Error");
                responseMessage.Add("Message", error.Message);
                return(responseMessage);
            }
        }
Пример #5
0
        public async Task <IActionResult> OnGetAsync(int id)
        {
            var resource = await _context.GetResourceAsync(id);

            if (resource == null)
            {
                TempData["Message"] = $"Resource not found. Id = {id}.";
                return(RedirectToPage("./Index"));
            }

            Resource = new EditResourceModel
            {
                Title       = resource.Metadata.ContainsKey("Title") ? resource.Metadata["Title"] : "",
                Location    = resource.Location,
                MediaType   = resource.Metadata.ContainsKey("MediaType") ? resource.Metadata["MediaType"] : "",
                Image       = resource.Metadata.ContainsKey("ImageURL") ? resource.Metadata["ImageURL"] : "",
                Description = resource.Metadata.ContainsKey("Description") ? resource.Metadata["Description"] : ""
            };

            return(Page());
        }
Пример #6
0
        public ActionResult Edit(int id)
        {
            var resource = new EditResourceModel(CurrentDatabase.Resources.FirstOrDefault(x => x.ResourceId == id));

            return(View(resource));
        }
Пример #7
0
        public ActionResult Edit(int id)
        {
            var resource = new EditResourceModel(DbUtil.Db.Resources.FirstOrDefault(x => x.ResourceId == id));

            return(View(resource));
        }