Пример #1
0
        public void LoadSubjects(EAV.Model.IModelContext context)
        {
            bool contextWasUnmodified = context.ObjectState == EAV.Model.ObjectState.Unmodified;

            HttpResponseMessage response = client.GetAsync(String.Format("api/metadata/contexts/{0}/subjects", context.ContextID.GetValueOrDefault())).Result;

            if (response.IsSuccessStatusCode)
            {
                context.Subjects.Clear();

                var subjects = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelSubject> >().Result;
                foreach (EAVModelLibrary.ModelSubject subject in subjects)
                {
                    subject.MarkUnmodified();

                    LoadSubjectEntity(subject);

                    context.Subjects.Add(subject);

                    subject.MarkUnmodified();
                }

                if (contextWasUnmodified)
                {
                    context.MarkUnmodified();
                }
            }
            else
            {
                throw (new ApplicationException("Attempt to get subjects failed."));
            }
        }
Пример #2
0
        public void LoadRootContainers(EAV.Model.IModelContext context)
        {
            bool contextWasUnmodified = context.ObjectState == EAV.Model.ObjectState.Unmodified;

            HttpResponseMessage response = client.GetAsync(String.Format("api/metadata/contexts/{0}/containers", context.ContextID.GetValueOrDefault())).Result;

            if (response.IsSuccessStatusCode)
            {
                context.Containers.Clear();

                var rootContainers = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelRootContainer> >().Result;
                foreach (EAVModelLibrary.ModelRootContainer rootContainer in rootContainers.OrderBy(it => it.Sequence))
                {
                    rootContainer.MarkUnmodified();

                    context.Containers.Add(rootContainer);

                    rootContainer.MarkUnmodified();
                }

                if (contextWasUnmodified)
                {
                    context.MarkUnmodified();
                }
            }
            else
            {
                throw (new ApplicationException("Attempt to get root containers failed."));
            }
        }
Пример #3
0
        public void SaveContext(EAV.Model.IModelContext context)
        {
            HttpResponseMessage response;

            if (context.ObjectState == EAV.Model.ObjectState.New)
            {
                response = client.PostAsJsonAsync <EAV.Store.IStoreContext>(String.Format("api/metadata/contexts"), context).Result;
                if (response.IsSuccessStatusCode)
                {
                    EAVModelLibrary.ModelContext newContext = response.Content.ReadAsAsync <EAVModelLibrary.ModelContext>().Result;

                    context.ContextID = newContext.ContextID;

                    context.MarkUnmodified();
                }
                else
                {
                    throw (new ApplicationException("Attempt to create context failed."));
                }
            }
            else if (context.ObjectState == EAV.Model.ObjectState.Modified)
            {
                response = client.PatchAsJsonAsync <EAV.Store.IStoreContext>("api/metadata/contexts", context).Result;
                if (response.IsSuccessStatusCode)
                {
                    context.MarkUnmodified();
                }
                else
                {
                    throw (new ApplicationException("Attempt to update context failed."));
                }
            }

            if (context.ObjectState == EAV.Model.ObjectState.Deleted)
            {
                response = client.DeleteAsync(String.Format("api/metadata/contexts/{0}", context.ContextID.GetValueOrDefault())).Result;
                if (response.IsSuccessStatusCode)
                {
                }
                else
                {
                    throw (new ApplicationException("Attempt to delete context failed."));
                }
            }
        }