Esempio n. 1
0
        public void Add(TEntity entity)
        {
            CreateUpdateActions();

            var entityAction = new EntityAction(entity, EntityState.Added, entity.GetType().Name, _dataComparer.ConvertObjectToPropertiesDictionary(entity));

            IDictionary <string, string> cleanProperties = _dataComparer.ConvertObjectToPropertiesDictionary(entity);

            Current.Add(new CleanEntity <TEntity>(entity, cleanProperties));

            OnActionCreated(new ActionCreatedEventArgs(entityAction));
        }
Esempio n. 2
0
        public async Task <IEnumerable <Form> > GetByNameAsync(string name)
        {
            CreateUpdateActions();

            var existingEntitiesMatchingCondition = Current.Where(p => p.Entity.Name == name).Select(p => p.Entity).ToList();

            string             getByNameSqlQuery   = _sqlGenerator.BuildGetByNameSqlQuery(typeof(Form).Name);
            IEnumerable <Form> resultsFromDataBase = await _connection.QueryAsync <Form>(getByNameSqlQuery, new { Name = name, ExcludedIds = existingEntitiesMatchingCondition.Select(p => p.Id).ToArray() }).ConfigureAwait(false);

            existingEntitiesMatchingCondition.AddRange(resultsFromDataBase);

            IEnumerable <CleanEntity <Form> > propertiesDictionaries = from entity in resultsFromDataBase
                                                                       let cleanEntity = _dataComparer.ConvertObjectToPropertiesDictionary(entity)
                                                                                         select new CleanEntity <Form>(entity, cleanEntity);

            Current.AddRange(propertiesDictionaries);

            return(existingEntitiesMatchingCondition);
        }