Esempio n. 1
0
        public async Task DeleteItemAsync(Dto partialDto)
        {
            var entitySet    = (IEntitySet <T>) this.dataContext.entitySets[this.entityTypeName];
            var dataOriginal = entitySet.FindByKey(partialDto);

            entitySet.DeleteEntity(dataOriginal);
            await this.dataAdapter.DeleteItemAsync(this.entityTypeName, partialDto);
        }
Esempio n. 2
0
        private T CreateNewItem(Dto dto)
        {
            var entity = new Entity(this.entityTypeName, dto);

            entity.Attach(this.entitySets, this.metadataCli);
            var derivedEntity = (T)Activator.CreateInstance(this.derivedEntityType, new object[] { entity });

            return(derivedEntity);
        }
Esempio n. 3
0
 public static Dto Extend(Dto target, Dto source, bool onlyExistingProperties = false)
 {
     foreach (var prop in source)
     {
         if (!(onlyExistingProperties && target.ContainsKey(prop.Key)))
         {
             target[prop.Key] = prop.Value;
         }
     }
     return(target);
 }
        public T GetSingleItem(Dto partialDto)
        {
            var derivedEntity = default(T);

            if (this.dataContext.entitySets.ContainsKey(this.entityTypeName))
            {
                var entitySet = (IEntitySet <T>) this.dataContext.entitySets[this.entityTypeName];
                derivedEntity = entitySet.FindByKey(partialDto /*partialEntity*/);
            }
            return(derivedEntity);
        }
Esempio n. 5
0
 private bool HaveSameKeysNavigation(Dto localDto, string[] keyLocal, Dto remoteDto, string[] keyRemote)
 {
     for (int i = 0; i < keyLocal.Length; i++)
     {
         if ((long)localDto[keyLocal[i]] != (long)remoteDto[keyRemote[i]])
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 6
0
 private bool HaveSameKeysLocal(Dto localDto, Dto remoteDto)
 {
     for (int i = 0; i < this.key.Length; i++)
     {
         if ((long)localDto[this.key[i]] != (long)remoteDto[this.key[i]])
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 7
0
        public async Task <T> GetSingleItemAsync(Dto partialDto, string[] expand = null)
        {
            //BusyIndicator.instance.start();
            var resultSingleSerialDataToken = await this.dataAdapter.LoadOneAsync(this.entityTypeName, partialDto, expand);

            var resultSingleSerialData = resultSingleSerialDataToken.ToObject <ResultSingleSerialData>();

            //BusyIndicator.instance.stop();
            var derivedEntity = this.dataContext.AttachSingleEntitiy(resultSingleSerialData);

            return((T)derivedEntity);
        }
Esempio n. 8
0
        public async Task <T> InsertItemAsync(Dto dto)
        {
            var keyNames     = this.metadataCli.EntityTypes[this.entityTypeName].Key;
            var dataOriginal = this.dataContext.CreateItemDetached <T>(this.entityTypeName);
            var patchItem    = this.GetPatchItemAsync(keyNames, dto, dataOriginal.entity.dto);
            //BusyIndicator.instance.start();
            var resultSingleSerialDataToken = await this.dataAdapter.PostItemAsync(this.entityTypeName, dto);

            var resultSingleSerialData = resultSingleSerialDataToken.ToObject <ResultSingleSerialData>();
            //BusyIndicator.instance.stop();
            var derivedEntity = this.dataContext.AttachSingleEntitiy(resultSingleSerialData);

            return((T)derivedEntity);
        }
Esempio n. 9
0
        private T Initialize(Dto dto, T derivedEntity)
        {
            //foreach (var prop in dto)
            //{
            //	entity[prop.Key] = prop.Value;
            //}

            // Nu este nevoie sa se copieze proprietatile.
            // Toate referintele externe se fac la Entity asadar se poate
            // inlocui referinta la Dto fara a afecta integritatea referentiala

            derivedEntity.entity.dto = dto;
            return(derivedEntity);
        }
Esempio n. 10
0
        public async Task <T> UpdateItemAsync(Dto partialDto)
        {
            var dataOriginal = this.dataContext.entitySets[this.entityTypeName].FindByKey(partialDto);

            // aplica modificarile datelor aflate in DataContext
            DalUtils.Extend(dataOriginal.entity.dto, partialDto);
            //BusyIndicator.instance.start();
            var resultSingleSerialDataToken = await this.dataAdapter.PutItemAsync(this.entityTypeName, dataOriginal.entity.dto);

            var resultSingleSerialData = resultSingleSerialDataToken.ToObject <ResultSingleSerialData>();
            //BusyIndicator.instance.stop();
            var derivedEntity = this.dataContext.AttachSingleEntitiy(resultSingleSerialData);

            return((T)derivedEntity);
        }
        public static Dto GetKeyFromData(string[] keyNames, Dto dto)
        {
            var result = new Dto();

            foreach (var keyName in keyNames)
            {
                if (dto.ContainsKey(keyName))
                {
                    result[keyName] = dto[keyName];
                }
                else
                {
                    throw new Exception("Invalid dto");
                }
            }
            return(result);
        }
Esempio n. 12
0
        /**
         * Insert single entity
         */
        public async Task <JToken> PostItemAsync(string entityTypeName, Dto patchItem)
        {
            var entitySetName = this.metadataCli.EntityTypes[entityTypeName].EntitySetName;
            var url           = this.apiUrl + "/crud/" + entitySetName;

            var jsonPatchItem = JsonConvert.SerializeObject(patchItem);
            var response      = await this.client.PostAsync(url, new StringContent(jsonPatchItem, Encoding.UTF8, "application/json"));

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var resultSingleSerialDataToken = JToken.Parse(json);
                return(resultSingleSerialDataToken);
            }
            return(null);
        }
Esempio n. 13
0
        public T CreateItemDetached <T>(string entityTypeName)
            where T : class, IDerivedEntity
        {
            //if (!this.entitySets.ContainsKey(entityTypeName))
            //{
            //    this.InitializeDataSet(entityTypeName);
            //}
            //var entityType = Type.GetType(this.metadata.Namespace + "." + entityTypeName);
            //var entity = Activator.CreateInstance(entityType);

            var entityType = this.metadataCli.EntityTypes[entityTypeName];
            var dto        = new Dto();

            dto.SetDefaultValues(entityType);
            var entity            = new Entity(entityTypeName, dto);
            var derivedEntityType = Type.GetType(this.@namespace + "." + entityTypeName);
            var derivedEntity     = (T)Activator.CreateInstance(derivedEntityType, new object[] { entity });

            return(derivedEntity);
        }
Esempio n. 14
0
        public T UpdateEntity(Dto dto)
        {
            T newItem;
            // se cauta elementul in colectia existenta
            var found = this.FindByKey(dto);

            if (found == null)
            {
                // daca nu a fost gasit se adauga in colectie
                newItem = this.CreateNewItem(dto);
                this.Items.Add(newItem);
            }
            else
            {
                // daca a fost gasit nu se inlocuieste ci se actualizaeza datale
                // astfel ca astfel ca referintele din dataViews existente sa nu se piarda.
                newItem = this.Initialize(dto, found);
            }

            return(newItem);
        }
Esempio n. 15
0
        /**
         * Delete single entity
         */
        public async Task <JToken> DeleteItemAsync(string entityTypeName, Dto partialEntity)
        {
            var entitySetName = this.metadataCli.EntityTypes[entityTypeName].EntitySetName;
            var keyNames      = this.metadataCli.EntityTypes[entityTypeName].Key;
            var url           = this.apiUrl + "/crud/" + entitySetName + "?" + QueryUtils.RenderQueryString(new QueryObject()
            {
                Keys = new List <Dto>()
                {
                    DataAdapterUtils.GetKeyFromData(keyNames, partialEntity)
                }.ToArray()
            });

            var response = await this.client.DeleteAsync(url);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var resultSingleSerialDataToken = JToken.Parse(json);
                return(resultSingleSerialDataToken);
            }
            return(null);
        }
Esempio n. 16
0
        /**
         * Update single entity
         */
        public async Task <JToken> PutItemAsync(string entityTypeName, Dto entity)
        {
            var entitySetName = this.metadataCli.EntityTypes[entityTypeName].EntitySetName;
            var keyNames      = this.metadataCli.EntityTypes[entityTypeName].Key;
            var url           = this.apiUrl + "/crud/" + entitySetName + "?" + QueryUtils.RenderQueryString(new QueryObject()
            {
                Keys = (new List <Dto>()
                {
                    DataAdapterUtils.GetKeyFromData(keyNames, entity)
                }).ToArray()
            });

            var jsonPatchItem = JsonConvert.SerializeObject(entity);
            var response      = await this.client.PutAsync(url, new StringContent(jsonPatchItem, Encoding.UTF8, "application/json"));

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var resultSingleSerialDataToken = JToken.Parse(json);
                return(resultSingleSerialDataToken);
            }
            return(null);
        }
 public Entity(string entityTypeName, Dto dto)
 {
     this.entityTypeName = entityTypeName;
     this.dto            = dto;
 }
Esempio n. 18
0
        public T FindByKey(Dto partialDto)
        {
            var derivedEntity = this.Items.FirstOrDefault((it) => this.HaveSameKeysLocal(it.entity.dto, partialDto));

            return((T)derivedEntity);
        }