public IHttpActionResult GetInboundICPFinal(int id) { bool validated = false; HttpRequestMessage request = ControllerContext.Request; // this seems to be same as request ValidateCredentials VC = new ValidateCredentials(); validated = VC.checkCreds(request); if (!validated) { return(Unauthorized()); } // user is good to go.. // now do something RiverWatchEntities RWDE = new RiverWatchEntities(); InboundICPFinal inboundICPFinal = RWDE.InboundICPFinals.Find(id); if (inboundICPFinal == null) { return(NotFound()); } return(Ok(inboundICPFinal)); }
public async Task <DeleteStationImageModel> DeleteBlob(DeleteStationImageModel model) { var deleteStationImageModel = new DeleteStationImageModel(); if (!String.IsNullOrEmpty(model.FileName)) { var container = BlobHelper.GetBlobContainer(); var blob = container.GetBlockBlobReference(model.FileName); bool deleted = false; string errorMessage = string.Empty; using (RiverWatchEntities _db = new RiverWatchEntities()) { var sameImageUrls = _db.StationImages .Where(si => si.FileUrl.Equals(model.FileUrl)) .ToList(); //if there is only one file, then delete it from the blob storage. if (sameImageUrls.Count() == 1) { await blob.DeleteIfExistsAsync(); } var stationImageToDelete = _db.StationImages.Find(model.ID); _db.StationImages.Remove(stationImageToDelete); _db.SaveChanges(); deleted = true; } if (!deleted) { errorMessage = "Image could not be deleted. Contact an Administrator if this problem continues."; } deleteStationImageModel = new DeleteStationImageModel() { ID = model.ID, FileName = model.FileName, FileUrl = model.FileUrl, Deleted = deleted, ErrorMessage = errorMessage }; return(deleteStationImageModel); } // Otherwise deleteStationImageModel = new DeleteStationImageModel() { ID = model.ID, FileName = model.FileName, Deleted = false, ErrorMessage = "Image could not be found. Contact an Administrator if this problem continues." }; return(deleteStationImageModel); }
private string GetImageName(int ID) { string imageName = string.Empty; using (RiverWatchEntities _db = new RiverWatchEntities()) { imageName = _db.StationImages .Where(si => si.ID == ID) .Select(si => si.FileName) .FirstOrDefault(); } return(imageName); }
public void LogError(string msg, string fromPage, string stackTrace, string loggedInUser, string comment) { RiverWatchEntities entities = new RiverWatchEntities(); ErrorLog EL = new ErrorLog(); EL.Date = DateTime.Now; EL.Message = msg; EL.Comment = comment; EL.StackTrace = stackTrace; EL.FromPage = fromPage; EL.LoggedInUser = loggedInUser ?? "Random acts of kindness"; entities.ErrorLogs.Add(EL); int result = entities.SaveChanges(); // for debugging }
public IHttpActionResult GetSampleExists(string samplenumber) { bool validated = false; HttpRequestMessage request = ControllerContext.Request; // this seems to be same as request ValidateCredentials VC = new ValidateCredentials(); validated = VC.checkCreds(request); if (!validated) { return(Unauthorized()); } RiverWatchEntities RWDE = new RiverWatchEntities(); return(Ok(RWDE.Samples.Count(e => e.SampleNumber == samplenumber) > 0)); }
public IHttpActionResult GetNewExpBarCodeExists(string Bcode) { bool validated = false; HttpRequestMessage request = ControllerContext.Request; // this seems to be same as request ValidateCredentials VC = new ValidateCredentials(); validated = VC.checkCreds(request); if (!validated) { return(Unauthorized()); } RiverWatchEntities RWDE = new RiverWatchEntities(); return(Ok(RWDE.NEWexpWaters.Count(e => e.MetalsBarCode == Bcode) > 0)); }
public IHttpActionResult GetInboundICPFinalExists(int id) { bool validated = false; HttpRequestMessage request = ControllerContext.Request; // this seems to be same as request ValidateCredentials VC = new ValidateCredentials(); validated = VC.checkCreds(request); if (!validated) { return(Unauthorized()); } RiverWatchEntities RWDE = new RiverWatchEntities(); return(Ok(RWDE.InboundICPFinals.Count(e => e.ID == id) > 0)); }
public void WriteToErrorLog(string msg, string fromPage, string stackTrace, string loggedInUser, string comment) { using (RiverWatchEntities _db = new RiverWatchEntities()) { ErrorLog eL = new ErrorLog(); eL.Date = DateTime.Now; eL.Message = msg; eL.Comment = comment; eL.StackTrace = stackTrace; eL.FromPage = fromPage; eL.LoggedInUser = loggedInUser; try { _db.ErrorLogs.Add(eL); int rows = _db.SaveChanges(); } catch (Exception ex) { string ms = ex.Message; } } }
public InboundICPFinal makeICP(string barcode, string type, int tableSampleID) { DateTime? newDate; Random RAND = new Random(); InboundICPFinal INB = new InboundICPFinal(); // create new data entity RiverWatchEntities entities = new RiverWatchEntities(); // get user input // string numberSample = txtNumSmp.Text.Trim(); // really bad name, perhaps we will have time to correct decimal mult = 0.0m; decimal V = 0; if (type.Substring(0, 1) == "0") // normal sample { mult = 100; } if (type.Substring(0, 1) == "1") // blank { mult = .1m; } if (type.Substring(0, 1) == "2") // duplicate { mult = 125; } try { INB.CODE = barcode; // make new barcode INB.DUPLICATE = type; // this is poorly named INB.tblSampleID = tableSampleID; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "AL" select z.Reporting.Value).FirstOrDefault(); INB.AL_D = (decimal)RAND.NextDouble() * V * mult; INB.AL_T = (decimal)INB.AL_D + (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "AS" select z.Reporting.Value).FirstOrDefault(); INB.AS_D = (decimal)RAND.NextDouble() * V * mult; INB.AS_T = (decimal)INB.AS_D + (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "CA" select z.Reporting.Value).FirstOrDefault(); INB.CA_D = (decimal)RAND.NextDouble() * V * mult; INB.CA_T = (decimal)INB.CA_D + (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "CD" select z.Reporting.Value).FirstOrDefault(); INB.CD_D = (decimal)RAND.NextDouble() * V * mult; INB.CD_T = (decimal)INB.CD_D + (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "CU" select z.Reporting.Value).FirstOrDefault(); INB.CU_D = (decimal)RAND.NextDouble() * V * mult; INB.CU_T = (decimal)INB.CU_D + (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "FE" select z.Reporting.Value).FirstOrDefault(); INB.FE_D = (decimal)RAND.NextDouble() * V * mult; INB.FE_T = (decimal)INB.FE_D + (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "K" select z.Reporting.Value).FirstOrDefault(); INB.K_D = (decimal)RAND.NextDouble() * V * mult; INB.K_T = (decimal)INB.K_D + (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "MG" select z.Reporting.Value).FirstOrDefault(); INB.MG_D = (decimal)RAND.NextDouble() * V * mult;; // make Total_Dups smaller than Disolved_Dups INB.MG_T = (decimal)INB.MG_D - (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "MN" select z.Reporting.Value).FirstOrDefault(); INB.MN_D = (decimal)RAND.NextDouble() * V * mult; INB.MN_T = (decimal)INB.MN_D + (decimal)RAND.NextDouble() - .5m;; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "NA" select z.Reporting.Value).FirstOrDefault(); INB.NA_D = (decimal)RAND.NextDouble() * V * mult; INB.NA_T = (decimal)INB.NA_D + (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "PB" select z.Reporting.Value).FirstOrDefault(); INB.PB_D = (decimal)RAND.NextDouble() * V * mult; INB.PB_T = (decimal)INB.PB_D + (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "SE" select z.Reporting.Value).FirstOrDefault(); INB.SE_D = (decimal)RAND.NextDouble() * V * mult; INB.SE_T = (decimal)INB.SE_D - (decimal)RAND.NextDouble() + .5m; V = (decimal)(from z in entities.tlkLimits where z.Element.ToUpper() == "ZN" select z.Reporting.Value).FirstOrDefault(); INB.ZN_D = (decimal)RAND.NextDouble() * V * mult;; // make Total_Dups smaller than Disolved_Dups INB.ZN_T = (decimal)INB.ZN_D - .5m; INB.Comments = "Created by hand for testing"; INB.ANADATE = DateTime.Now; newDate = DateTime.Now.AddDays(-2); INB.DATE_SENT = newDate; INB.CreatedBy = "Windows App Test System"; newDate = DateTime.Now.AddDays(-6); INB.CreatedDate = newDate.Value; INB.COMPLETE = true; INB.Saved = false; INB.Edited = false; INB.Valid = true; return(INB); } catch (Exception ex) { string nam = "ICP BC Generator"; string msg = ex.Message; LogErrror LE = new LogErrror(); LE.LogError(msg, "MakeIPCInbound", ex.StackTrace.ToString(), nam, "From Windows Form makeICPIbound Data generator"); return(INB); // for the compiler.. } }
public async Task <IHttpActionResult> PostInboundICPFinal(InboundICPFinal inboundICPFinal) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } RiverWatchEntities RWDE = new RiverWatchEntities(); InboundICPOrigional IO = new InboundICPOrigional(); int res = 0; int id = 0; bool validated = false; string conStr = RWDE.Database.Connection.ConnectionString; HttpRequestMessage request = ControllerContext.Request; // this seems to be same as request ValidateCredentials VC = new ValidateCredentials(); validated = VC.checkCreds(request); if (!validated) { return(Unauthorized()); } try { RWDE.InboundICPFinals.Add(inboundICPFinal); // RWDE.InboundICPOrigionals.Add(inboundICPFinal); res = await RWDE.SaveChangesAsync(); id = inboundICPFinal.ID; // get from last write // now copy to origional table and save // would rather do this than use a stored proc that could get lost later IO.AL_D = inboundICPFinal.AL_D; IO.AL_T = inboundICPFinal.AL_T; IO.ANADATE = inboundICPFinal.ANADATE; IO.AS_D = inboundICPFinal.AS_D; IO.AS_T = inboundICPFinal.AS_T; IO.CA_D = inboundICPFinal.CA_D; IO.CA_T = inboundICPFinal.CA_T; IO.CD_D = inboundICPFinal.CD_D; IO.CD_T = inboundICPFinal.CD_T; IO.CODE = inboundICPFinal.CODE; IO.Comments = inboundICPFinal.Comments; IO.COMPLETE = inboundICPFinal.COMPLETE; IO.CreatedBy = inboundICPFinal.CreatedBy; IO.CreatedDate = inboundICPFinal.CreatedDate; IO.CU_D = inboundICPFinal.CU_D; IO.CU_T = inboundICPFinal.CU_T; IO.DATE_SENT = inboundICPFinal.DATE_SENT; IO.DUPLICATE = inboundICPFinal.DUPLICATE; IO.Edited = inboundICPFinal.Edited; IO.FE_D = inboundICPFinal.FE_D; IO.FE_T = inboundICPFinal.FE_T; IO.K_D = inboundICPFinal.K_D; IO.K_T = inboundICPFinal.K_T; IO.MG_D = inboundICPFinal.MG_D; IO.MG_T = inboundICPFinal.MG_T; IO.MN_D = inboundICPFinal.MN_D; IO.MN_T = inboundICPFinal.MN_T; IO.NA_D = inboundICPFinal.NA_D; IO.NA_T = inboundICPFinal.NA_T; IO.PB_D = inboundICPFinal.PB_D; IO.PB_T = inboundICPFinal.PB_T; IO.Saved = inboundICPFinal.Saved; IO.SE_D = inboundICPFinal.SE_D; IO.SE_T = inboundICPFinal.SE_T; IO.tblSampleID = inboundICPFinal.tblSampleID; IO.Valid = inboundICPFinal.Valid; IO.ZN_D = inboundICPFinal.ZN_D; IO.ZN_T = inboundICPFinal.ZN_T; RWDE.InboundICPOrigionals.Add(IO); RWDE.SaveChanges(); } catch (Exception ex) { string msg = string.Format("Data base write failed with error: {0}", ex.Message); return(InternalServerError(ex)); } //return updated inboundICPFinal object with Id return(Ok(inboundICPFinal)); //not sure what this was being used for so I commented it out? returning the URI of the created resource? //return CreatedAtRoute("DefaultApi", new { id = inboundICPFinal.ID }, inboundICPFinal); }
public async Task <UpdatePrimaryStationImageModel> UpdatedStationImage(UpdatePrimaryStationImageModel model) { using (RiverWatchEntities _db = new RiverWatchEntities()) { var updatePrimaryStationImageModel = new UpdatePrimaryStationImageModel(); bool enforcePrimary = false; enforcePrimary = _db.StationImageTypes.Find(model.ImageTypeID).EnforcePrimary; var stationImages = _db.StationImages .Where(si => si.StationID == model.StationID) .ToList <StationImage>(); if (stationImages.Count() == 0) { updatePrimaryStationImageModel = new UpdatePrimaryStationImageModel() { ID = model.ID, StationID = model.StationID, Primary = model.Primary, ImageTypeID = model.ImageTypeID, Description = model.Description, PhysHabYear = model.PhysHabYear, Updated = false, ErrorMessage = "No Station Images were found to update." }; } else { foreach (var stationImage in stationImages) { //the station image being updated if (stationImage.ID == model.ID) { if (!enforcePrimary) { stationImage.Primary = false; } else { stationImage.Primary = model.Primary; } stationImage.ImageType = model.ImageTypeID; stationImage.Description = model.Description; stationImage.ModifiedBy = model.ModifiedBy; stationImage.ModifiedDate = DateTime.Now; stationImage.PhysHabYear = model.PhysHabYear; } else if (model.Primary && enforcePrimary && (stationImage.ID != model.ID)) { stationImage.Primary = false; } await _db.SaveChangesAsync(); updatePrimaryStationImageModel = new UpdatePrimaryStationImageModel() { ID = model.ID, StationID = model.StationID, Primary = model.Primary, ImageTypeID = model.ImageTypeID, Description = model.Description, PhysHabYear = model.PhysHabYear, Updated = true, ErrorMessage = string.Empty }; } } return(updatePrimaryStationImageModel); } }
private bool SaveImage(List <StationImageUploadModel> uploadList) { bool exists = true; int stationID = uploadList[0].StationID; using (RiverWatchEntities _db = new RiverWatchEntities()) { int stationIDFromStationTable = 0; if (uploadList.Count > 0) { stationIDFromStationTable = _db.Stations .Where(s => s.ID == stationID) .Select(s => s.ID) .FirstOrDefault(); } if (stationIDFromStationTable > 0) { StationImage newStationImage = new StationImage(); bool primary = false; bool enforcePrimary = false; foreach (var uploadModel in uploadList) { string fileExt = Path.GetExtension(uploadModel.FileName); long fileSizeInKb = uploadModel.FileSizeInKb; primary = uploadModel.Primary; enforcePrimary = _db.StationImageTypes.Find(uploadModel.ImageTypeID).EnforcePrimary; if (!enforcePrimary) { primary = false; } else { primary = uploadModel.Primary; } var stationImage = new StationImage() { StationID = uploadModel.StationID, FileName = uploadModel.FileName, FileUrl = uploadModel.FileUrl, FileExt = fileExt, FileSizeInBytes = uploadModel.FileSizeInBytes, FileSizeInKb = uploadModel.FileSizeInKb, Primary = primary, ImageType = uploadModel.ImageTypeID, Description = uploadModel.Description, PhysHabYear = uploadModel.PhysHabYear, CreatedBy = uploadModel.User, CreatedDate = DateTime.Now }; _db.StationImages.Add(stationImage); _db.SaveChanges(); newStationImage = stationImage; } //set all other to not primary if the new one is primary if (primary) { var stationImages = _db.StationImages .Where(si => si.StationID == stationID && !si.FileName.Equals(newStationImage.FileName)) .ToList <StationImage>(); foreach (var stationImage in stationImages) { stationImage.Primary = false; _db.SaveChanges(); } } } else { exists = false; } } return(exists); }