Exemplo n.º 1
0
        protected override IComondModul <IMyEntity> СommandStart(IComondModul <IMyEntity> comond)
        {
            if (comond.Action == TypeComond.Get)
            {
                IEnumerable <IMyEntity> user = mainContext.GetEntity(comond.TypeModel);

                comond.SetAnswer(user);
            }
            else if (comond.Action == TypeComond.Сreate)
            {
                IMyEntity         ответ = mainContext.CreatEntity(comond.TypeModel);
                IList <IMyEntity> user  = new List <IMyEntity> {
                    ответ
                };
                comond.SetAnswer(user);
            }
            else if (comond.Action == TypeComond.Remove)
            {
                mainContext.RemoveEntity(comond.Data);
                comond.SetAnswer(comond.Data);
            }
            else if (comond.Action == TypeComond.Save)
            {
                mainContext.SaveChangesAsync();
            }
            else if (comond.Action == TypeComond.GetTable)
            {
                comond.Metadata = mainContext.GetTable();
            }
            return(comond);
        }
Exemplo n.º 2
0
        protected override IComondModul <IMyEntity> СommandEnd(IComondModul <IMyEntity> comond)
        {
            if (comond.Action == TypeComond.Get)
            {
                IEnumerable <IMyEntity> врем = (IEnumerable <IMyEntity>)comond.Answer;

                ICollection <IMyEntity> observable = (ICollection <IMyEntity>)GetObserCollection(comond.TypeModel);
                IEnumerable <IMyEntity> Удалить    = observable.ToList().Where(r => врем.Where(r2 => r2.Id == r.Id).Count() == 0).ToList();
                IEnumerable <IMyEntity> Добавить   = врем.Where(r => observable.Where(r2 => r2.Id == r.Id).Count() == 0).ToList();
                СhangeObservable(observable, Добавить, Удалить);
                comond.SetAnswer(observable);
                dictionaryobservable[comond.TypeModel] = observable;
            }
            else if (comond.Action == TypeComond.Remove)
            {
                ICollection <IMyEntity> observable = (ICollection <IMyEntity>)GetObserCollection(comond.TypeModel);
                IEnumerable <IMyEntity> врем       = comond.Answer;
                IEnumerable <IMyEntity> Удалить    = observable.ToList().Where(r => врем.Where(r2 => r2.Id == r.Id).Count() != 0).ToList();
                СhangeObservable(observable, null, Удалить);
                comond.SetAnswer(Удалить);
            }
            else if (comond.Action == TypeComond.Сreate)
            {
                ICollection <IMyEntity> observable = (ICollection <IMyEntity>)GetObserCollection(comond.TypeModel);
                IEnumerable <IMyEntity> врем       = comond.Answer;
                IEnumerable <IMyEntity> Добавить   = врем.Where(r => observable.Where(r2 => r2.Id == r.Id).Count() == 0).ToList();
                СhangeObservable(observable, Добавить, null);
                comond.SetAnswer(Добавить);
            }

            return(base.СommandEnd(comond));
        }
Exemplo n.º 3
0
        protected override IComondModul <IMyEntity> СommandStart(IComondModul <IMyEntity> comond)
        {
            if (comond.Action == TypeComond.Get && cacheEntity != null && cacheEntity.Count > 0)
            {
                IEnumerable <IMyEntity> entity = comond.Sort(cacheEntity);

                if (entity.Count() > 0)
                {
                    comond.SetAnswer(entity);
                }
            }
            return(base.СommandStart(comond));
        }
Exemplo n.º 4
0
        protected override IComondModul <IMyEntity> СommandStart(IComondModul <IMyEntity> comond)
        {
            if (comond.Action == TypeComond.Get)
            {
                if (data.ContainsKey(comond.TypeModel))
                {
                    comond.SetAnswer(data[comond.TypeModel].ToList());
                }
            }
            else if (comond.Action == TypeComond.Сreate)
            {
                ConstructorInfo ci      = comond.TypeModel.GetConstructor(new Type[] { });
                object          создали = ci.Invoke(new object[] { });
                if (создали is IMyEntity новый)
                {
                    IList <IMyEntity> myEntities = new List <IMyEntity> {
                        новый
                    };
                    comond.SetAnswer(myEntities);
                    if (data.ContainsKey(comond.TypeModel))
                    {
                        ((IList <IMyEntity>)data[comond.TypeModel]).Add(новый);
                    }
                    else
                    {
                        IDictionary <Type, IEnumerable <IMyEntity> > newData = data.ToDictionary(r => r.Key, r2 => r2.Value);
                        newData.Add(comond.TypeModel, myEntities);
                        data = newData;
                    }
                }


                throw new Exception("Создоваемый объект не неаследует IMyEntity");
            }
            else if (comond.Action == TypeComond.Remove)
            {
                if (data.ContainsKey(comond.TypeModel))
                {
                    foreach (IMyEntity entity in comond.Data)
                    {
                        if (((IList <IMyEntity>)data[comond.TypeModel]).Contains(entity))
                        {
                            ((IList <IMyEntity>)data[comond.TypeModel]).Remove(entity);
                        }
                    }
                }

                comond.SetAnswer(comond.Data.ToList());
            }

            if (dataInt.ContainsKey(comond.Action))
            {
                dataInt[comond.Action] = dataInt[comond.Action] + 1;
            }
            else
            {
                dataInt.Add(comond.Action, 1);
            }

            return(comond);
        }