Exemple #1
0
        public void mapExcel()
        {
            CropHendler m_CropHendler = new CropHendler(new GenericRepository <Crop>());
            var         filePath      = @"C:\Users\user\Desktop\excel\rawData.csv";
            var         data          = File.ReadLines(filePath).Select(x => x.Split(',')).ToArray();

            addAllMissingCrops(data[0]);
            int currentId;

            int[] ids = convertNamesToIds(data[0]);



            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                CropsConstrainsRepository cropsContains = new CropsConstrainsRepository(context);

                for (int i = 1; i < data.Length; i++)
                {
                    currentId = getCropIdByName(data[i][0]);

                    for (int j = 1; j < data[i].Length; j++)
                    {
                        CropConstrains cc = new CropConstrains();
                        cc.Crop1_Id   = currentId;
                        cc.Crop2_Id   = ids[j];
                        cc.NumOfYears = int.Parse(data[i][j]);

                        cropsContains.AddRow(cc);
                        cropsContains.Save();
                    }
                }
            }
        }
        public IHttpActionResult DeleteCoordinate(int i_CoordinateID)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();
                bool ok = true;

                try
                {
                    m_CoordinateHendler.DeleteRow(i_CoordinateID, context);
                }
                catch
                {
                    ok       = false;
                    response = StatusCode(System.Net.HttpStatusCode.ServiceUnavailable);
                }
                if (ok)
                {
                    List <ILightWeight> coordinatesToSend = m_CoordinateHendler.GetAllTable(context) as List <ILightWeight>;
                    response = Ok(coordinatesToSend);
                }

                return(response);
            }
        }
        public IHttpActionResult PostSite(Site i_PostedSite)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();
                bool ok = true;

                try
                {
                    m_SiteHendler.PostNewRow(i_PostedSite, context);
                }
                catch
                {
                    ok       = false;
                    response = StatusCode(System.Net.HttpStatusCode.ServiceUnavailable);
                }
                if (ok)
                {
                    List <ILightWeight> sitesToSend = m_SiteHendler.GetAllTable(context) as List <ILightWeight>;
                    response = Ok(sitesToSend);
                }

                return(response);
            }
        }
        public IHttpActionResult GetLayersNamesAndIDS()
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult    response     = StatusCode(System.Net.HttpStatusCode.ServiceUnavailable);
                List <ILightWeight>  layers       = m_LayerHendler.GetAllTable(context) as List <ILightWeight>;
                List <LayerIdentity> layersToSend = null;

                if (layers.Count > 0)
                {
                    layersToSend = new List <LayerIdentity>();

                    foreach (ILightWeight layer in layers)
                    {
                        layersToSend.Add(new LayerIdentity()
                        {
                            ID   = (layer as LightWeightLayer).ID,
                            Name = (layer as LightWeightLayer).Name
                        });
                    }

                    response = Ok(layersToSend);
                }

                return(response);
            }
        }
Exemple #5
0
        public List <Crop> predictCropsToGrow(int i_SiteID)
        {
            List <Crop> allAllowedCrops = new List <Crop>();

            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                CropRepository            cropRepo          = new CropRepository(context);
                List <Crop>               allCrops          = cropRepo.GetNegevEntityCollection() as List <Crop>;
                List <CropYearPair>       cropYearsPairs    = GetCropsBySiteId(i_SiteID);
                CropsConstrainsRepository cropConstrainRepo = new CropsConstrainsRepository(context);

                foreach (Crop crop in allCrops)
                {
                    bool allowGrow = true;

                    foreach (CropYearPair cyp in cropYearsPairs)
                    {
                        int allowedYears = GetYears(crop.ID, cyp._Crop.ID);
                        if (!determineIfCropAllowed(allowedYears, cyp.Year))
                        {
                            allowGrow = false;
                            break;
                        }
                    }

                    if (allowGrow)
                    {
                        allAllowedCrops.Add(crop);
                    }
                }
            }

            return(allAllowedCrops);
        }
Exemple #6
0
        public IHttpActionResult UpdateSiteByYear(SiteByYear i_SiteByYearToModofied)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();
                bool ok = true;

                try
                {
                    m_SiteByYearHendler.UpdateRow(i_SiteByYearToModofied, context);
                }
                catch
                {
                    ok       = false;
                    response = StatusCode(System.Net.HttpStatusCode.ServiceUnavailable);
                }
                if (ok)
                {
                    List <ILightWeight> sitesByYearsToSend = m_SiteByYearHendler.GetAllTable(context) as List <ILightWeight>;
                    response = Ok(sitesByYearsToSend);
                }

                return(response);
            }
        }
        public IHttpActionResult UpdateCrop(Crop i_CropToBeModified)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();
                bool ok = true;

                try
                {
                    m_CropHendler.UpdateRow(i_CropToBeModified, context);
                }
                catch
                {
                    response = StatusCode(System.Net.HttpStatusCode.ServiceUnavailable);
                    ok       = false;
                }
                if (ok)
                {
                    List <ILightWeight> cropsToSend = m_CropHendler.GetAllTable(context) as List <ILightWeight>;
                    response = Ok(cropsToSend);
                }

                return(response);
            }
        }
        public IHttpActionResult UpdateLayer(Layer i_ModifideLayer)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();
                bool ok = true;

                try
                {
                    m_LayerHendler.UpdateRow(i_ModifideLayer, context);
                }
                catch
                {
                    response = StatusCode(System.Net.HttpStatusCode.ServiceUnavailable);
                    ok       = false;
                }
                if (ok)
                {
                    List <ILightWeight> layersToSend = m_LayerHendler.GetAllTable(context) as List <ILightWeight>;
                    response = Ok(layersToSend);
                }

                return(response);
            }
        }
Exemple #9
0
 int getCropIdByName(string name)
 {
     using (EntitiesNegev4 context = new EntitiesNegev4())
     {
         var x = (from y in context.Crops where y.Name.Equals(name) select y).ToList();
         return(x[0].ID);
     }
 }
Exemple #10
0
        public int GetYears(int i_PotentialCropId, int i_GrownCropId)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                var numOfYears =
                    (from x in context.CropConstrains
                     where x.Crop1_Id.Equals(i_PotentialCropId) && x.Crop2_Id.Equals(i_GrownCropId)
                     select x.NumOfYears).ToList();

                return(numOfYears.Count == 0 ? (is_not_exist_rull_allowed ? -1 : 100000) : numOfYears[0]);
            }
        }
        public IHttpActionResult GetAllLayers()
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response     = NotFound();
                List <Layer>      layersToSend = m_LayerHendler.GetAllTable(context) as List <Layer>;

                if (layersToSend.Count > 0)
                {
                    response = Ok(layersToSend);
                }

                return(response);
            }
        }
Exemple #12
0
        public IHttpActionResult GetSiteByYear(int i_SiteByYearID)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response         = NotFound();
                SiteByYear        siteByYearToSend = m_SiteByYearHendler.GetRowByID(i_SiteByYearID, context) as SiteByYear;

                if (siteByYearToSend != null)
                {
                    response = Ok(siteByYearToSend);
                }

                return(response);
            }
        }
Exemple #13
0
        public IHttpActionResult GetAllSitesByYears()
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response           = NotFound();
                List <SiteByYear> sitesByYearsToSend = m_SiteByYearHendler.GetAllTable(context) as List <SiteByYear>;

                if (sitesByYearsToSend.Count > 0)
                {
                    response = Ok(sitesByYearsToSend);
                }

                return(response);
            }
        }
Exemple #14
0
        public IHttpActionResult GetCropByID(int id)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response   = StatusCode(System.Net.HttpStatusCode.ServiceUnavailable);
                ILightWeight      cropToSend = m_CropHendler.GetRowByID(id, context);

                if (cropToSend != null)
                {
                    response = Ok(cropToSend);
                }

                return(response);
            }
        }
        public IHttpActionResult GetCropByID(int id)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = NotFound();
                Crop cropToSend            = m_CropHendler.GetRowByID(id, context) as Crop;

                if (cropToSend != null)
                {
                    response = Ok(cropToSend);
                }

                return(response);
            }
        }
        public IHttpActionResult GetCoordinate(int i_CoordinateID)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response         = NotFound();
                Coordinate        coordinateToSend = m_CoordinateHendler.GetRowByID(i_CoordinateID, context) as Coordinate;

                if (coordinateToSend != null)
                {
                    response = Ok(coordinateToSend);
                }

                return(response);
            }
        }
        public IHttpActionResult GetAllCoordinates()
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response          = NotFound();
                List <Coordinate> coordinatesToSend = m_CoordinateHendler.GetAllTable(context) as List <Coordinate>;

                if (coordinatesToSend.Count > 0)
                {
                    response = Ok(coordinatesToSend);
                }

                return(response);
            }
        }
Exemple #18
0
        public IHttpActionResult GetAllSites()
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult   response    = StatusCode(System.Net.HttpStatusCode.ServiceUnavailable);
                List <ILightWeight> sitesToSend = m_SiteHendler.GetAllTable(context) as List <ILightWeight>;

                if (sitesToSend.Count > 0)
                {
                    response = Ok(sitesToSend);
                }

                return(response);
            }
        }
Exemple #19
0
        public IHttpActionResult GetSite(int i_SiteID)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response   = StatusCode(System.Net.HttpStatusCode.ServiceUnavailable);
                ILightWeight      siteToSend = m_SiteHendler.GetRowByID(i_SiteID, context);

                if (siteToSend != null)
                {
                    response = Ok(siteToSend);
                }

                return(response);
            }
        }
        public IHttpActionResult GetLayer(int i_LayerID)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response    = NotFound();
                Layer             layerToSend = null;
                layerToSend = m_LayerHendler.GetRowByID(i_LayerID, context) as Layer;

                if (layerToSend != null)
                {
                    response = Ok(layerToSend);
                }

                return(response);
            }
        }
Exemple #21
0
        public IHttpActionResult PostSiteByYear(SiteByYear i_PostedSiteByYear)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();

                try
                {
                    m_SiteByYearHendler.PostNewRow(i_PostedSiteByYear, context);
                }
                catch
                {
                    response = BadRequest("could not post...");
                }

                return(response);
            }
        }
Exemple #22
0
        private void addCrop(string name)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                CropRepository            crops         = new CropRepository(context);
                List <Crop>               cropsDataBase = crops.GetNegevEntityCollection() as List <Crop>;
                CropsConstrainsRepository ccrs          = new CropsConstrainsRepository(context);

                Crop c = new Crop();

                c.Name        = name;
                c.Quantity    = 0;
                c.SiteByYears = null;
                c.Description = "";
                crops.AddRow(c);
                crops.Save();
            }
        }
Exemple #23
0
        public IHttpActionResult UpdateSiteByYear(SiteByYear i_SiteByYearToModofied)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();

                try
                {
                    m_SiteByYearHendler.UpdateRow(i_SiteByYearToModofied, context);
                }
                catch
                {
                    response = BadRequest("could not update...");
                }

                return(response);
            }
        }
Exemple #24
0
        public IHttpActionResult DeleteSiteByYear(int i_SiteByYearID)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();

                try
                {
                    m_SiteByYearHendler.DeleteRow(i_SiteByYearID, context);
                }
                catch
                {
                    response = BadRequest("could not delete...");
                }

                return(response);
            }
        }
Exemple #25
0
        public IHttpActionResult UpdateSite(Site i_ModifideSite)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();

                try
                {
                    m_SiteHendler.UpdateRow(i_ModifideSite, context);
                }
                catch
                {
                    response = BadRequest("could not update...");
                }

                return(response);
            }
        }
        public IHttpActionResult UpdateLayer(Layer i_ModifideLayer)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();

                try
                {
                    m_LayerHendler.UpdateRow(i_ModifideLayer, context);
                }
                catch
                {
                    response = BadRequest("could not update...");
                }

                return(Ok());
            }
        }
        public IHttpActionResult DeleteCoordinate(int i_CoordinateID)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();

                try
                {
                    m_CoordinateHendler.DeleteRow(i_CoordinateID, context);
                }
                catch
                {
                    response = BadRequest("could not delete");
                }

                return(response);
            }
        }
        public IHttpActionResult UpdateCoordinte(Coordinate i_CoordinteToModified)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();

                try
                {
                    m_CoordinateHendler.UpdateRow(i_CoordinteToModified, context);
                }
                catch
                {
                    response = BadRequest("could not update...");
                }

                return(response);
            }
        }
        public IHttpActionResult PostCoordinate(Coordinate i_PostedCoordinate)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult response = Ok();

                try
                {
                    m_CoordinateHendler.PostNewRow(i_PostedCoordinate, context);
                }
                catch
                {
                    response = BadRequest("could not post");
                }

                return(response);
            }
        }
        public IHttpActionResult PostNewCrop(Crop i_PostedCrop)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                IHttpActionResult   response    = Ok();
                IHttpHendlerRequest cropHendler = IHttpHendlerRequestFactory.CreateHttpRequestHendler("Crop");

                try
                {
                    cropHendler.PostNewRow(i_PostedCrop, context);
                }
                catch
                {
                    response = BadRequest("could not post...");
                }

                return(response);
            }
        }