Exemple #1
0
        public FisherGPS GetFisherGPS(Fisher fisher, GPS gps,
                                      ProjectSetting projectSetting,
                                      DateTime dateTimeDeparted, out EntityValidationMessage errorMessage)
        {
            errorMessage = new EntityValidationMessage("");
            FisherGPS rv = null;

            foreach (FisherGPS fg in FisherGPSCollection.OrderBy(p => p.DateAssigned))
            {
                if (fg.Fisher.FisherID == fisher.FisherID &&
                    fg.GPS.ID == gps.ID &&
                    fg.ProjectSetting.ProjectID == projectSetting.ProjectID)
                {
                    if (fg.DateReturned != null)
                    {
                    }
                    rv = fg;
                    break;
                }
            }
            if (rv == null)
            {
                errorMessage = new EntityValidationMessage("No matching Fisher-GPS record was found. Check date and time departed");
            }
            return(rv);
        }
        public Dictionary <GPS, AssignedGPSDetails> GetAllGPSAssignedToFisherEx(Fisher f, ProjectSetting p)
        {
            var dict = new Dictionary <GPS, AssignedGPSDetails>();

            foreach (var fg in BSCEntities.FisherGPSViewModel.FisherGPSCollection
                     .Where(t => t.Fisher.FisherID == f.FisherID)
                     .Where(t => t.ProjectSetting.ProjectID == p.ProjectID)
                     .OrderBy(t => t.GPS.AssignedName)
                     .ThenByDescending(t => t.DateAssigned))

            {
                var agpsd = new AssignedGPSDetails();

                if (dict.Keys.Contains(fg.GPS))
                {
                    dict[fg.GPS].NumberOfTimesAssigned++;
                    //dict[fg.GPS].AddDateToRange((DateTime)fg.DateAssigned, fg.DateReturned);
                    dict[fg.GPS].AddFisherGPS(fg);
                }
                else
                {
                    //agdr = new AssignedGPSDateRange(fg.GPS, (DateTime)fg.DateAssigned, fg.DateReturned, 1);
                    agpsd = new AssignedGPSDetails(fg.GPS, fg, 1);
                    dict.Add(fg.GPS, agpsd);
                }
            }

            return(dict);
        }
Exemple #3
0
 public FisherGPS GetFisherGPS(Fisher f, GPS g, ProjectSetting p)
 {
     return((from fg in FisherGPSCollection
             where fg.Fisher.FisherID == f.FisherID
             where fg.GPS.ID == g.ID
             where fg.ProjectSetting.ProjectID == p.ProjectID
             select fg).FirstOrDefault());
 }
 public GPS GetSuggestedGPS(Fisher f, ProjectSetting p)
 {
     return(BSCEntities.FisherGPSViewModel.FisherGPSCollection
            .Where(t => t.Fisher.FisherID == f.FisherID)
            .Where(t => t.ProjectSetting.ProjectID == p.ProjectID)
            .OrderByDescending(t => t.DateAssigned)
            .Select(t => t.GPS).FirstOrDefault());
 }
 public List <GPS> GetAllGPSAssignedToFisher(Fisher f, ProjectSetting p)
 {
     return(BSCEntities.FisherGPSViewModel.FisherGPSCollection
            .Where(x => x.ProjectSetting.ProjectID == p.ProjectID)
            .Where(x => x.Fisher.FisherID == f.FisherID)
            .GroupBy(t => t.GPS.ID)
            .Select(t => t.First().GPS).ToList());
 }
        public void AddRecordToRepo(Fisher fisher)
        {
            if (fisher == null)
            {
                throw new ArgumentNullException("Error: The argument is Null");
            }

            FisherCollection.Add(fisher);
        }
 public FisherGPS(string id, GPS gps, Fisher fisher, ProjectSetting projectSetting, DateTime?dateAssigned, DateTime?dateReturned)
 {
     RowID          = id;
     GPS            = gps;
     Fisher         = fisher;
     ProjectSetting = projectSetting;
     DateAssigned   = dateAssigned;
     DateReturned   = dateReturned;
 }
Exemple #8
0
 public List <FisherGPS> GetAllFisherGPS(Fisher f = null)
 {
     if (f == null)
     {
         return(FisherGPSCollection.ToList());
     }
     else
     {
         return(FisherGPSCollection.Where(t => t.Fisher.FisherID == f.FisherID).ToList());
     }
 }
Exemple #9
0
 public FisherGPS LatestReturnedDateByFisher(Fisher f)
 {
     try
     {
         return(GetAllFisherGPS(f)
                .OrderByDescending(t => t.DateReturned).First());
     }
     catch
     {
         return(null);
     }
 }
        public Dictionary <GPS, int> GetAllGPSAssignedToFisherEx1(Fisher f, ProjectSetting p)
        {
            var tempList = from g in BSCEntities.FisherGPSViewModel.FisherGPSCollection
                           where g.Fisher.FisherID == f.FisherID
                           where g.ProjectSetting.ProjectID == p.ProjectID
                           group g.GPS by g.GPS into t
                           select new
            {
                key   = t.Key,
                value = t.Count()
            };

            return(tempList.ToDictionary(x => x.key, x => x.value));
        }
        public bool EntityValidated(Fisher fisher, out List <string> messages)
        {
            messages = new List <string>();

            if (fisher.FisherName.Length < 5)
            {
                messages.Add("Fisher's name must be at least 5 characters long");
            }

            if (fisher.LandingSite == null)
            {
                messages.Add("Fisher's landing site cannot be empty");
            }

            return(messages.Count == 0);
        }
        public bool Add(Fisher f)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Insert into Fisher (FisherName, LandingSite,FisherId, FishingBoatName)
                           Values 
                           ('{f.FisherName}',{{{f.LandingSite.LandingSiteID}}},{{{f.FisherID}}}, '{f.FishingBoatName}')";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
        public void UpdateRecordInRepo(Fisher fisher)
        {
            if (fisher.FisherID == null)
            {
                throw new Exception("Error: ID cannot be null");
            }

            int index = 0;

            while (index < FisherCollection.Count)
            {
                if (FisherCollection[index].FisherID == fisher.FisherID)
                {
                    FisherCollection[index] = fisher;
                    break;
                }
                index++;
            }
        }
        public bool Update(Fisher f)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Update Fisher set
                                FisherName = '{f.FisherName}',
                                LandingSite = {{{f.LandingSite.LandingSiteID}}},
                                FishingBoatName = '{f.FishingBoatName}'
                            WHERE FisherId={{{f.FisherID}}}";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
        private List <Fisher> getFishers()
        {
            List <Fisher> listFishers = new List <Fisher>();
            var           dt          = new DataTable();

            using (var conection = new OleDbConnection(Global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    string query = $@"SELECT * from Fisher";

                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        listFishers.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            Fisher f = new Fisher();
                            f.FisherID        = dr["FisherId"].ToString();
                            f.FisherName      = dr["FisherName"].ToString();
                            f.FishingBoatName = dr["FishingBoatName"].ToString();
                            var ls = BSCEntities.LandingSiteViewModel.GetLandingSite(dr["LandingSite"].ToString());
                            if (ls != null)
                            {
                                f.LandingSite = ls;
                            }
                            listFishers.Add(f);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }

            return(listFishers);
        }
Exemple #16
0
        public bool CanAssignGPS(Fisher f)
        {
            if (FisherGPSCollection.Count > 0)
            {
                if (GetAllFisherGPS(f).Count == 0)
                {
                    return(true);
                }
                else

                {
                    var maxRow = FisherGPSCollection
                                 .Where(d => d.Fisher.FisherID == f.FisherID)
                                 .MaxBy(d => d.DateAssigned).ToList()[0];
                    return(maxRow.DateReturned != null);
                }
            }
            else
            {
                return(true);
            }
        }
Exemple #17
0
 public List <Sampling> GetAllSamplings(Fisher f)
 {
     return(SamplingCollection
            .Where(t => t.FisherGPS.Fisher.FisherID == f.FisherID).ToList());
 }
 public bool CanDeleteEntity(Fisher f)
 {
     //return !Fishers.FisherIsPairedWithGPS(f);
     return(BSCEntities.FisherGPSViewModel.FisherGPSCollection
            .Where(t => t.Fisher.FisherID == f.FisherID).ToList().Count == 0);
 }