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

            LocationCollection locationcollection = null;

            try
            {
                locationcollection = data.LocationCollectionRepository.GetByID(key);
                if (locationcollection == null)
                {
                    NLogWriter.LogMessage(LogType.Error, LogMsg + "Locationcollection cannot be found");
                    throw new Exception("Locationcollection cannot be found");
                }
                data.LocationCollectionRepository.Delete(key);
                data.Save();
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception deleting locationcollection by key = '" + Convert.ToString(key) + "' :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception deleting locationcollection by key = '" + Convert.ToString(key) + "' :: " + ex.ToString()),
                    ReasonPhrase = "Unable to delete locationcollection"
                };
                throw new HttpResponseException(resp);
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 记录异常日志
        /// </summary>
        /// <param name="ex">异常</param>
        /// <param name="url">请求地址</param>
        /// <param name="param">请求参数</param>
        private static void WriteLog(Exception ex, string url, string param)
        {
            ILogger log = new NLogWriter(NLog.LogManager.GetCurrentClassLogger());

            log.Error(ex, _logFormat, ex.Message, ex.StackTrace, url, param);
            //  LogWriter.WriteLog(string.Format(_logFormat, ex.Message, ex.StackTrace, url, param), _logDir, ExceptionHelper.ExceptionLevel.Exception);
        }
Exemplo n.º 3
0
        // POST: odata/LocationCollections
        public IHttpActionResult Post(LocationCollection locationCollection)
        {
            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.LocationCollectionRepository.Insert(locationCollection);
                data.Save();
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception creating locationcollection :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception creating locationcollection :: " + ex.ToString()),
                    ReasonPhrase = "Unable to create locationcollection"
                };
                throw new HttpResponseException(resp);
            }

            return(Created(locationCollection));
        }
Exemplo n.º 4
0
        // PUT: odata/LocationCollections(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <LocationCollection> patch)
        {
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            LocationCollection locationcollection = null;

            try
            {
                Validate(patch.GetChangedPropertyNames());

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

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

                patch.Put(locationcollection);
                try
                {
                    data.Save();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    if (!LocationCollectionExists(key))
                    {
                        NLogWriter.LogMessage(LogType.Error, LogMsg + "DbUpdateConcurrencyException putting locationcollection by ID '" + Convert.ToString(key) + "' - Not Found :: " + ex.ToString());
                        throw new Exception("DbUpdateConcurrencyException putting locationcollection by ID = '" + Convert.ToString(key) + "' - Not Found :: " + ex.ToString());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception updating locationcollection :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception updating locationcollection :: " + ex.ToString()),
                    ReasonPhrase = "Unable to udpate locationcollection"
                };
                throw new HttpResponseException(resp);
            }
            return(Updated(locationcollection));
        }
Exemplo n.º 5
0
        public IQueryable <LocationCollection> GetLocationCollections()
        {
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            if (Properties.Settings.Default.DebugMode)
            {
                NLogWriter.LogMessage(LogType.Debug, LogMsg + "Get All LocationCollections");
            }
            return(data.LocationCollectionRepository.GetAll());
        }
Exemplo n.º 6
0
        private bool LocationCollectionExists(int key)
        {
            string LogMsg = MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().ToString() + " :: ";

            try
            {
                return(data.LocationCollectionRepository.Exists(key));
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception checking locationcollection existence by key = '" + Convert.ToString(key) + "' :: " + ex.ToString());
                return(false);
            }
        }
Exemplo n.º 7
0
        // GET: LocationCollections
        public ActionResult Index()
        {
            //var locationCollections = db.LocationCollections.Include(l => l.Collection).Include(l => l.Location);
            //return View(locationCollections.ToList());
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            LocationCollectionsViewModel lcvm = new LocationCollectionsViewModel();

            try
            {
                lcvm.fclist = db.LocationCollections.Include(r => r.Collection).Include(r => r.Location).Include(r => r.Collection.CollectionName).Include(r => r.Location.LocationName).ToList();
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception getting floating collections :: " + ex.ToString());
                ModelState.AddModelError("", "Unhandled Exception occurred");
                ModelState.AddModelError("", ex.ToString());
            }
            return(View(lcvm));
        }
Exemplo n.º 8
0
        public SingleResult <LocationCollection> GetLocationCollection([FromODataUri] int key)
        {
            string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                            this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

            List <LocationCollection> locationcollections = new List <LocationCollection>();

            try
            {
                locationcollections.Add(data.LocationCollectionRepository.GetByID(key));
            }
            catch (Exception ex)
            {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception retrieving locationcollection by ID = '" + Convert.ToString(key) + "' :: " + ex.ToString());
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("Exception retrieving locationcollection by ID:: " + ex.ToString()),
                    ReasonPhrase = "Locationcollection not found"
                };
                throw new HttpResponseException(resp);
            }
            return(SingleResult.Create(locationcollections.AsQueryable()));
        }
Exemplo n.º 9
0
    // GET: Shelvings/Index/5
    public ActionResult Index(int? id)
    {
      //var shelvings = db.Shelvings.Include(s => s.LocationCollection).Include(s => s.ShelfType);
      //return View(shelvings.ToList());
      string LogMsg = this.ControllerContext.RouteData.Values["controller"].ToString() + "Controller." +
                      this.ControllerContext.RouteData.Values["action"].ToString() + " :: ";

      ShelvingIndexViewModel sivm = new ShelvingIndexViewModel();

      try
      {
        sivm.slist = db.Shelvings.Where(l => l.LocationID == id).Include(r => r.ShelfType).Include(r => r.LocationCollection).Include(r => r.LocationID).ToList();
        try
        {
          sivm.stypes = db.ShelfTypes.ToList();
          try
          {
            sivm.location = db.Locations.Where(l => l.LocationID == id).FirstOrDefault().LocationName; 
            try
            {
              sivm.loccol = db.LocationCollections.Where(l => l.LocationID == id).ToList();
              try
              {
                sivm.col = db.Collections.ToList();

                //foreach (Shelving s in sivm.slist)
                //{
                //  var lcid = s.LocationCollectionID;
                //  var colid = sivm.loccol.
                //  s.LocationCollection = db.Collections.Where(l => l.CollectionID == s.LocationCollectionID).FirstOrDefault().Collection.CollectionName;
                //}
              }
              catch (Exception ex)
              {
                NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception getting collection :: " + ex.ToString());
                ModelState.AddModelError("", "Unhandled Exception occurred");
                ModelState.AddModelError("", ex.ToString());
              }
            }
            catch (Exception ex)
            {
              NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception getting location collection :: " + ex.ToString());
              ModelState.AddModelError("", "Unhandled Exception occurred");
              ModelState.AddModelError("", ex.ToString());
            }
          }
          catch (Exception ex)
          {
            NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception getting location :: " + ex.ToString());
            ModelState.AddModelError("", "Unhandled Exception occurred");
            ModelState.AddModelError("", ex.ToString());
          }
        }
        catch (Exception ex)
        {
          NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception getting shelf types :: " + ex.ToString());
          ModelState.AddModelError("", "Unhandled Exception occurred");
          ModelState.AddModelError("", ex.ToString());
        }
      }
      catch (Exception ex)
      {
        NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception getting floating collections :: " + ex.ToString());
        ModelState.AddModelError("", "Unhandled Exception occurred");
        ModelState.AddModelError("", ex.ToString());
      }
      return View(sivm);
    }