예제 #1
0
        // DELETE: odata/Shelvings(5)
        public IHttpActionResult Delete([FromODataUri] int key)
        {
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            Shelving shelving = null;

            try
            {
                shelving = data.ShelvingRepository.GetByID(key);
                if (shelving == null)
                {
                    NLogWriter.LogMessage(LogType.Error, LogMsg + "Shelving cannot be found");
                    throw new Exception("Shelving cannot be found");
                }
                data.ShelvingRepository.Delete(key);
                data.Save();
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception deleting shelving by key = '" + Convert.ToString(key) + "' :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception deleting shelving by key = '" + Convert.ToString(key) + "' :: " + ex.ToString()),
                    ReasonPhrase = "Unable to delete shelving"
                };
                throw new HttpResponseException(resp);
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        // POST: odata/Shelvings
        public IHttpActionResult Post(Shelving shelving)
        {
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            try
            {
                if (!ModelState.IsValid)
                {
                    NLogWriter.LogMessage(LogType.Error, LogMsg + "Invalid ModelState");
                    throw new Exception("Invalid modelstate");
                }

                data.ShelvingRepository.Insert(shelving);
                data.Save();
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception creating shelving :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception creating shelving :: " + ex.ToString()),
                    ReasonPhrase = "Unable to create shelving"
                };
                throw new HttpResponseException(resp);
            }

            return(Created(shelving));
        }
예제 #3
0
        // PUT: odata/Shelvings(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <Shelving> patch)
        {
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            Shelving shelving = null;

            try
            {
                Validate(patch.GetChangedPropertyNames());

                if (!ModelState.IsValid)
                {
                    NLogWriter.LogMessage(LogType.Error, LogMsg + "Invalid ModelState");
                    throw new Exception("Invalid modelstate");
                }

                shelving = data.ShelvingRepository.GetByID(key);
                if (shelving == null)
                {
                    NLogWriter.LogMessage(LogType.Error, LogMsg + "Unable to find shelving by Key = '" + Convert.ToString(key) + "'");
                    throw new Exception("Unable to find shelving by key");
                }

                patch.Put(shelving);
                try
                {
                    data.Save();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    if (!ShelvingExists(key))
                    {
                        NLogWriter.LogMessage(LogType.Error, LogMsg + "DbUpdateConcurrencyException putting shelving by ID '" + Convert.ToString(key) + "' - Not Found :: " + ex.ToString());
                        throw new Exception("DbUpdateConcurrencyException putting shelving by ID = '" + Convert.ToString(key) + "' - Not Found :: " + ex.ToString());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception updating shelving :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception updating shelving :: " + ex.ToString()),
                    ReasonPhrase = "Unable to udpate shelving"
                };
                throw new HttpResponseException(resp);
            }
            return(Updated(shelving));
        }