public IHttpActionResult PutInboundICPFinal(int id, InboundICPFinal inboundICPFinal) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != inboundICPFinal.ID) { return(BadRequest()); } db.Entry(inboundICPFinal).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!InboundICPFinalExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
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); }
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 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 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); }
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); }