예제 #1
0
        public async Task <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
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InboundICPFinalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
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);
        }
예제 #3
0
        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);
            }
        }