Beispiel #1
0
        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 <IHttpActionResult> PostStationImage()
        {
            try
            {
                bool validated             = false;
                HttpRequestMessage request = ControllerContext.Request;

                ValidateCredentials VC = new ValidateCredentials();
                validated = VC.checkCreds(request);
                if (!validated)
                {
                    return(Unauthorized());
                }

                // This endpoint only supports multipart form data
                if (!Request.Content.IsMimeMultipartContent("form-data"))
                {
                    return(StatusCode(HttpStatusCode.UnsupportedMediaType));
                }

                //access form data
                var provider = await Request.Content.ReadAsMultipartAsync <InMemoryMultipartFormDataStreamProvider>(new InMemoryMultipartFormDataStreamProvider());

                var stationImageUploadModel = provider.UploadedStationImageUploadModel;

                //access files
                IList <HttpContent> files = provider.Files;

                if (stationImageUploadModel.StationID <= 0)
                {
                    return(BadRequest());
                }

                // Call service to perform upload, then check result to return as content
                var result = await _service.UploadBlobs(files, stationImageUploadModel);

                if (result != null && result.Count > 0)
                {
                    return(Ok(result));
                }

                // Otherwise
                return(BadRequest());
            }
            catch (Exception ex)
            {
                HandleErrors(ex, "StationImageController_PostStationImage", "", "");
                return(InternalServerError(ex));
            }
        }
        public async Task <IHttpActionResult> UpdateStationImage(UpdatePrimaryStationImageModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                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());
                }

                if (model.ID <= 0)
                {
                    return(BadRequest());
                }

                // Call service to perform update, then check result to return as content
                var updatePrimaryStationImageModel = await _service.UpdatedStationImage(model);

                if (updatePrimaryStationImageModel != null)
                {
                    if (updatePrimaryStationImageModel.Updated)
                    {
                        return(Ok(updatePrimaryStationImageModel));
                    }
                    else
                    {
                        return(BadRequest(updatePrimaryStationImageModel.ErrorMessage));
                    }
                }

                // Otherwise
                return(BadRequest());
            }
            catch (Exception ex)
            {
                HandleErrors(ex, "StationImageController_UpdateStationImage", "", "");
                return(InternalServerError(ex));
            }
        }
Beispiel #4
0
        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));
        }
Beispiel #5
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));
        }
Beispiel #6
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));
        }
Beispiel #7
0
        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);
        }