Example #1
0
        //private Expression<Func<Contact, bool>> getExpression(List<ColumnFilterInfo> filters)
        //{
        //    var discountFilter = "album => album.Quantity > 0";
        //    var options = ScriptOptions.Default.AddReferences(typeof(Album).Assembly);

        //    Func<Album, bool> discountFilterExpression = await CSharpScript.EvaluateAsync<Func<Album, bool>>(discountFilter, options);

        //    var discountedAlbums = albums.Where(discountFilterExpression);
        //    Expression<Func<Contact, bool>> where = t => true;
        //    foreach (ColumnFilterInfo filter in filters) {
        //        if (filter.EntityName == typeof(Contact).Name) {
        //            switch (filter.FilterType) {
        //                case FilterTypeEnum.Equals.ToString():
        //                    where.
        //                    break;
        //            }
        //        }
        //    }


        //}

        private Contact MapToEntity(Dictionary <string, object> model, IEnumerable <AddedColumn> AddedColumns)
        {
            //try
            //{
            List <AddedColumn> ContactAddedColumns = AddedColumns.Where(t => t.EntityName == typeof(Contact).Name).ToList();
            List <AddedColumn> CompanyAddedColumns = AddedColumns.Where(t => t.EntityName == typeof(Company).Name).ToList();
            Contact            contact             = new Contact();

            contact.Name = model["Name"].ToString();

            foreach (AddedColumn column in ContactAddedColumns)
            {
                try
                {
                    BsonElement bsonElement = new BsonElement(column.ColumnName, (BsonValue)model[column.ColumnName]);
                    contact.AddedColumns.Add(bsonElement);
                }
                catch { }
            }

            contact.Company = new List <Company>();
            //JsonObject comp = JsonObject.Parse(model["Company"].ToString());

            JsonArrayObjects companyList = JsonObject.ParseArray(model["Company"].ToString());

            if (companyList.GroupBy(n => n["Name"]).Any(c => c.Count() > 1))
            {
                throw new Exception("Company name field must be unique!");
            }
            foreach (JsonObject element in companyList.AsEnumerable())
            {
                Company company = new Company();
                company.Name = element["Name"].ToString();

                company.ID = _sequence.GetNextSequenceValue(typeof(Company).Name);

                company.NumberOfEmployees = int.Parse(element["NumberOfEmployees"].ToString());
                foreach (AddedColumn column in CompanyAddedColumns)
                {
                    try
                    {
                        BsonElement bsonElement = new BsonElement(column.ColumnName, (BsonValue)element[column.ColumnName]);
                        company.AddedColumns.Add(bsonElement);
                    }
                    catch { }
                }
                contact.Company.Add(company);
            }
            return(contact);
            //}
            //catch (Exception ex)
            //{
            //    throw new Exception("Error mapping contact company fields !!");
            //}
        }
Example #2
0
        private AddedColumn MapToEntity(AddedColumnCreateModel model)
        {
            AddedColumn entity = new AddedColumn();

            entity.ID         = (int)_sequence.GetNextSequenceValue(typeof(AddedColumn).Name);
            entity.ColumnName = model.ColumnName;
            entity.ColumnType = model.ColumnType;
            entity.EntityName = model.EntityName;
            return(entity);
        }
Example #3
0
 public override async Task <Company> Add(Company company)
 {
     company.ID = sequence.GetNextSequenceValue(typeof(Company).Name);
     return(await base.Add(company));
 }
Example #4
0
 public override async Task <Contact> Add(Contact contact)
 {
     contact.ID = sequence.GetNextSequenceValue(typeof(Contact).Name);
     return(await base.Add(contact));
 }