Esempio n. 1
0
        public HttpResponseMessage Post(Governor gov)
        {
            if (gov == null)
                return Request.CreateResponse(HttpStatusCode.NotFound);

            _rep.Create(gov);
            var response = Request.CreateResponse(HttpStatusCode.Created, gov);

            var odataPath = Request.GetODataPath();
            if (odataPath == null)
            {
                throw new InvalidOperationException("There is no ODataPath in the request.");
            }
            var entitySetPathSegment = odataPath.Segments.FirstOrDefault() as EntitySetPathSegment;
            if (entitySetPathSegment == null)
            {
                throw new InvalidOperationException("ODataPath doesn't start with EntitySetPathSegment.");
            }

            response.Headers.Location = new Uri(Url.ODataLink(entitySetPathSegment, new KeyValuePathSegment(ODataUriUtils.ConvertToUriLiteral(gov.Id, ODataVersion.V3))));

            //response.Headers.Location = new Uri(Url.ODataLink(new EntitySetPathSegment("Governors"), new KeyValuePathSegment(gov.Id.ToString())));

            return response;
        }
Esempio n. 2
0
        public object Create(BLL.Governor o)
        {
            var dto = _mapper.Map <BLL.Governor, Governor>(o);

            _db.AddToGovernors(dto);
            _db.SaveChanges();
            return(o);
        }
Esempio n. 3
0
        public void Update(BLL.Governor o)
        {
            var proxy = o as IDtoProxy;

            if (proxy != null)
            {
                _db.UpdateObject(proxy.Dto);
                _db.SaveChanges(System.Data.Services.Client.SaveChangesOptions.ReplaceOnUpdate);
            }
        }
Esempio n. 4
0
        public void Delete(BLL.Governor o)
        {
            var proxy = o  as IDtoProxy;

            if (proxy != null)
            {
                _db.DeleteObject(proxy.Dto);
                _db.SaveChanges();
            }
        }
Esempio n. 5
0
 public int GetIndexOf(BLL.Governor o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     return(_db.Governors.AddFilters(filters).AddOrders(orderBy).IndexOf(o.Id));
 }
Esempio n. 6
0
 public HttpResponseMessage Put([FromODataUri] Guid key, Governor update)
 {
     _rep.Update(update);
     return Request.CreateResponse(HttpStatusCode.NoContent);
 }