public bool CreateSurveyDetail(BirdSurveyDetails item) { bool result = false; try { using (RCID_DWHEntities context = new RCID_DWHEntities()) { Bird_SurveyDetail efItem = new Bird_SurveyDetail() { SurveyID = item.SurveyID, SpeciesID = item.SpeciesID, SurveyDetailCount = item.SurveyDetailCount }; context.Bird_SurveyDetail.Add(efItem); if (context.SaveChanges() > 0) { return(true); } } } catch (Exception e) { throw e; } return(result); }
public bool InactivateSurveyDetail(BirdSurveyDetails item) { bool result = false; try { using (RCID_DWHEntities context = new RCID_DWHEntities()) { Bird_SurveyDetail efItem = context.Bird_SurveyDetail.Where(b => b.SurveyID == item.SurveyID && b.SpeciesID == item.SpeciesID).FirstOrDefault(); if (efItem == null) { return(result); } efItem.SurveyDetailActive = false; if (context.SaveChanges() > 0) { result = true; } } } catch (Exception) { } return(result); }
public static List <BirdSurvey> ParseFile(string filepath) { List <BirdSurvey> surveyList = new List <BirdSurvey>(); try { using (XLWorkbook workBook = new XLWorkbook(filepath)) { IXLWorksheet workSheet = workBook.Worksheet(1); foreach (IXLRow row in workSheet.Rows()) { switch (row.RowNumber()) { //first three rows are survey headers case 1: foreach (IXLCell cell in row.Cells()) { string value = cell.Value.ToString(); //starting a survey if (!value.Equals("Observer")) { BirdSurvey item = new BirdSurvey(); item.SurveyorName = value; //TODO remove this line! there should be a way to get the climate id for this item item.ClimateID = 1; surveyList.Add(item); } } break; case 2: foreach (IXLCell cell in row.Cells()) { string value = cell.Value.ToString(); //add date to survey if (!value.Equals("Date")) { DateTime date = cell.GetDateTime(); BirdSurvey item = surveyList[cell.Address.ColumnNumber - 2]; item.SurveyDate = date; } } break; case 3: foreach (IXLCell cell in row.Cells()) { string value = cell.Value.ToString(); //add date to survey if (!value.Equals("Location")) { BirdSurvey item = surveyList[cell.Address.ColumnNumber - 2]; item.SamplePointAreaName = value; } } break; // after three rows, survey details start default: string speciesName = ""; foreach (IXLCell cell in row.Cells()) { //all rows except the last one which is a total row if (cell.Address.ColumnNumber == 1) { speciesName = cell.Value.ToString(); if (speciesName.Equals("TOTAL SPECIES")) { break; } //this is the last row } else { if (!cell.IsEmpty()) { BirdSurvey parent = surveyList[cell.Address.ColumnNumber - 2]; BirdSurveyDetails detail = new BirdSurveyDetails(); detail.SpeciesName = speciesName; detail.SurveyDetailCount = cell.Value.CastTo <int>(); if (parent.Details == null) { parent.Details = new List <BirdSurveyDetails>(); } parent.Details.Add(detail); } } } break; } } } return(surveyList); } catch (Exception e) { throw e; } }