Exemplo n.º 1
0
        ///<include file='docs.xml' path='doc/members/member[@name="M:GenericRepositoryAndService.Repository.GenericRepository`1.SetNewParamFromContextList(System.Data.Entity.DbContext,GenericRepositoryAndService.Repository.GenericRepository{`0}.CustomParam)"]/*'/>
        private CustomParam SetNewParamFromContextList(DbContext newContext, CustomParam customParam)
        {
            var newvalue = Convert.ChangeType(
                Activator.CreateInstance(typeof(List <>).MakeGenericType(customParam.TypeofElement)),
                typeof(List <>).MakeGenericType(customParam.TypeofElement)
                );

            if (customParam.Value != null)
            {
                foreach (object item in customParam.Value as IList)
                {
                    object newitem;
                    if (item is BaseEntity entity)
                    {
                        newitem = newContext.Set(customParam.TypeofElement).Find(entity.Id);
                    }
                    else
                    {
                        object[] objs = GenericToolsTypeAnalysis.GetKeysValuesForType(item, customParam.TypeofElement);
                        newitem = GenericToolsCRUD.FindByKeysInNewContextForType(customParam.TypeofElement, newContext, objs);
                    }
                    ((IList)newvalue).Add(newitem);
                }
            }
            return(new CustomParam(
                       newvalue,
                       customParam.TypeofElement,
                       customParam.PropertyName,
                       customParam.Prop,
                       true
                       ));
        }
Exemplo n.º 2
0
        ///<include file='docs.xml' path='doc/members/member[@name="M:GenericRepositoryAndService.Service.GenericService`1.UpdateOne(`0,System.String,System.Object)"]/*'/>
        public void UpdateOne(T t, string propertyName, object newValue)
        {
            dynamic temprep = _repository;

            GenericToolsCRUD.PrepareUpdateOne(temprep.DataContext, t, propertyName);
            _repository.UpdateOne(t, propertyName, newValue);
        }
Exemplo n.º 3
0
        ///<include file='docs.xml' path='doc/members/member[@name="M:GenericRepositoryAndService.Service.GenericService`1.Update(`0)"]/*'/>
        public void Update(T t)
        {
            dynamic temprep = _repository;

            object[] objs = GenericToolsCRUD.PrepareUpdate(temprep.DataContext, t);
            _repository.Update(t, objs);
        }
Exemplo n.º 4
0
        ///<include file='docs.xml' path='doc/members/member[@name="M:GenericRepositoryAndService.Service.GenericService`1.Delete(`0)"]/*'/>
        public void Delete(T t)
        {
            dynamic temprep = _repository;

            GenericToolsCRUD.PrepareDelete <T>(temprep.DataContext, GenericToolsTypeAnalysis.GetKeysValues(t));
            _repository.Delete(t);
        }
Exemplo n.º 5
0
        ///<include file='docs.xml' path='doc/members/member[@name="M:GenericRepositoryAndService.Service.GenericService`1.Delete(System.Object[])"]/*'/>
        public void Delete(params object[] objs)
        {
            GenericToolsTypeAnalysis.CheckIfObjectIsKey <T>(objs);
            dynamic temprep = _repository;

            GenericToolsCRUD.PrepareDelete <T>(temprep.DataContext, objs);
            _repository.Delete(objs);
        }
Exemplo n.º 6
0
        ///<include file='docs.xml' path='doc/members/member[@name="M:GenericRepositoryAndService.Repository.GenericRepository`1.SetNewParamFromContextNotList(System.Data.Entity.DbContext,GenericRepositoryAndService.Repository.GenericRepository{`0}.CustomParam)"]/*'/>
        private CustomParam SetNewParamFromContextNotList(DbContext newContext, CustomParam customParam)
        {
            object newvalue = null;

            if (customParam.Value != null)
            {
                if (customParam.Value is BaseEntity entity)
                {
                    newvalue = newContext.Set(customParam.TypeofElement).Find(entity.Id);
                }
                else
                {
                    object[] objs = GenericToolsTypeAnalysis.GetKeysValuesForType(customParam.Value, customParam.TypeofElement);
                    newvalue = GenericToolsCRUD.FindByKeysInNewContextForType(customParam.TypeofElement, newContext, objs);
                }
            }
            return(new CustomParam(
                       newvalue,
                       customParam.TypeofElement,
                       customParam.PropertyName,
                       customParam.Prop,
                       false
                       ));
        }
Exemplo n.º 7
0
 ///<include file='docs.xml' path='doc/members/member[@name="M:GenericRepositoryAndService.Service.GenericService`1.Save(`0)"]/*'/>
 public void Save(T t)
 {
     object[] objs = GenericToolsCRUD.PrepareSave(t);
     _repository.Save(t, objs);
 }