Пример #1
0
        public void PutLocation(int id, Location locationToUpdate)
        {
            Logger.InfoFormat("Update(" + id.ToString() + ") operation");

            locationToUpdate.Id = id;
            try
            {
                Repository.Update<Location>(locationToUpdate);
            }
            catch (Exception ex)
            {
                Logger.Error("Error when updating the item " + id.ToString(), ex);
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
        }
Пример #2
0
        public void TestSave()
        {
            IItemRepository repository = container.Resolve<IItemRepository>();

            //Item item = repository.Get<Item>(1);

            Item item = new Item();
            item.Title = "Test save " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            item.Value = DateTime.Now.Second;
            item.Moment = DateTime.Now;

            Location location = new Location();
            location.Name="BCN";
            repository.Add<Location>(location);

            item.Location = location;

            Item item2 = repository.Add<Item>(item);
            Item item3 = repository.Add<Item>(item2);

            //item3.Location += " modification";
            repository.Update<Item>(item3);
        }
Пример #3
0
        public HttpResponseMessage PostLocation(Location newLocation)
        {
            Logger.InfoFormat("Post(" + newLocation + ") operation");
            if (newLocation == null)
            {
                Logger.Error("Error when adding a item. It is null");
                throw new HttpResponseException(HttpStatusCode.Conflict);
            }
            else
            {
                Repository.Add<Location>(newLocation);
                var response = Request.CreateResponse<Location>(HttpStatusCode.Created, newLocation);

                string uri = Url.Link("DefaultApi", new { id = newLocation.Id });
                response.Headers.Location = new Uri(uri);
                return response;
            }
        }