Ejemplo n.º 1
0
        public void delete(Object obj)
        {
            using (var db = new Dbase())
            {
                if (obj.GetType() == typeof(Area))
                {
                    Area area       = (Area)obj;
                    Area areaDelete = db.areas.Where(a => a.name == area.name).FirstOrDefault <Area>();

                    db.areas.Remove(areaDelete);
                }
                else if (obj.GetType() == typeof(Cooperative))
                {
                    Cooperative cooperative       = (Cooperative)obj;
                    Cooperative cooperativeDelete = db.cooperatives.Where(c => c.name == cooperative.name).FirstOrDefault <Cooperative>();

                    db.cooperatives.Remove(cooperativeDelete);
                }
                else if (obj.GetType() == typeof(Plant))
                {
                    Plant plant       = (Plant)obj;
                    Plant plantDelete = db.plants.Where(p => p.name == plant.name).FirstOrDefault <Plant>();

                    db.plants.Remove(plantDelete);
                }
                else if (obj.GetType() == typeof(Regions))
                {
                    Regions region       = (Regions)obj;
                    Regions regionDelete = db.regions.Where(r => r.name == region.name).FirstOrDefault <Regions>();

                    db.regions.Remove(regionDelete);
                }
                else if (obj.GetType() == typeof(CooperativeDataValues))
                {
                    CooperativeDataValues cooperativeDataValues = (CooperativeDataValues)obj;
                    db.cooperativeDataValues.Remove(cooperativeDataValues);
                }
                else if (obj.GetType() == typeof(CooperativeDataContent))
                {
                    CooperativeDataContent cooperativeDataContent = (CooperativeDataContent)obj;
                    db.cooperativeDataContent.Remove(cooperativeDataContent);
                }


                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public Object add(Object obj)
        {
            object resultObj = null;

            using (var db = new Dbase())
            {
                if (obj.GetType() == typeof(Area))
                {
                    Area area = (Area)obj;
                    db.areas.Add(area);
                    db.SaveChanges();

                    resultObj = area;
                }
                else if (obj.GetType() == typeof(Cooperative))
                {
                    Cooperative cooperative = (Cooperative)obj;
                    db.cooperatives.Add(cooperative);
                    db.SaveChanges();

                    resultObj = cooperative;
                }
                else if (obj.GetType() == typeof(Plant))
                {
                    Plant plant = (Plant)obj;
                    db.plants.Add(plant);
                    db.SaveChanges();

                    resultObj = plant;
                }
                else if (obj.GetType() == typeof(Regions))
                {
                    Regions region = (Regions)obj;
                    db.regions.Add(region);
                    db.SaveChanges();

                    resultObj = region;
                }
                else if (obj.GetType() == typeof(DataValues))
                {
                    DataValues dataValue = (DataValues)obj;
                    db.dataValues.Add(dataValue);
                    db.SaveChanges();

                    resultObj = dataValue;
                }
                else if (obj.GetType() == typeof(DataContent))
                {
                    DataContent dataContent = (DataContent)obj;
                    db.dataContents.Add(dataContent);
                    db.SaveChanges();

                    resultObj = dataContent;
                }
                else if (obj.GetType() == typeof(CooperativeDataValues))
                {
                    CooperativeDataValues cooperativeDataValues = (CooperativeDataValues)obj;
                    db.cooperativeDataValues.Add(cooperativeDataValues);
                    db.SaveChanges();

                    resultObj = cooperativeDataValues;
                }
                else if (obj.GetType() == typeof(CooperativeDataContent))
                {
                    CooperativeDataContent cooperativeDataContent = (CooperativeDataContent)obj;
                    db.cooperativeDataContent.Add(cooperativeDataContent);
                    db.SaveChanges();

                    resultObj = cooperativeDataContent;
                }
                else if (obj.GetType() == typeof(DataType))
                {
                    DataType dataType = (DataType)obj;
                    db.dataTypes.Add(dataType);
                    db.SaveChanges();

                    resultObj = dataType;
                }

                return(resultObj);
            }
        }