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

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

            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(val.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 ActivateEmptyModel()
 {
     AssetValue a = new AssetValue();
     a.TakingDate = DateTime.Today;
     a.InsuranceType = BL.Model.Enums.InsuranceType.OPS;
     //a.GovernorId = g.Id;
     a.Governor = null;
     return a;
 }
Esempio n. 3
0
        public void Delete(BLL.AssetValue o)
        {
            var proxy = o as IDtoProxy;

            if (proxy != null)
            {
                _db.DeleteObject(proxy.Dto);
                _db.SaveChanges();
            }
        }
Esempio n. 4
0
        public object Create(BLL.AssetValue o)
        {
            var dto = _mapper.Map <BLL.AssetValue, AssetValue>(o);

            dto.GovernorId = o.Governor.Id;
            //dto.Governor = _db.Governors.GetById(dto.GovernorId);
            _db.AddToAssets(dto);
            _db.SaveChanges();
            return(o);
        }
Esempio n. 5
0
        public int GetIndexOf(BLL.AssetValue o, FilterParameterCollection filters, SortParameterCollection orderBy)
        {
            orderBy.DefaultOrder         = defaultSorting;
            orderBy.PropertyNameResolver = propResolver;
            if (filters != null)
            {
                filters.PropertyNameResolver = propResolver;
            }

            return(_db.Assets.AddFilters(filters).AddOrders(orderBy).IndexOf(o.Id));
        }
Esempio n. 6
0
        public override BaseModel ShallowCopy()
        {
            var ret = new AssetValue();

            ret.Id                 = this.Id;
            ret.TakingDate         = this.TakingDate;
            ret.Value              = this.Value;
            ret.CashFlow           = this.CashFlow;
            ret.InsuranceTypeValue = this.InsuranceTypeValue;
            ret.GovernorId         = this.GovernorId;
            ret.Governor           = this.Governor;
            return(ret);
        }
Esempio n. 7
0
        public void Update(BLL.AssetValue o)
        {
            var proxy = o as IDtoProxy;

            if (proxy != null)
            {
                Guid govId = o.Governor.Id;
                var  dto   = proxy.Dto as AssetValue;

                if (govId != dto.GovernorId)
                {
                    dto.GovernorId = govId;
                    dto.Governor   = _db.Governors.GetById(govId);
                    o.Governor     = ProxyActivator.CreateProxy <Governor, BLL.Governor>(dto.Governor);
                    //_db.SetLink(dto, "Governor", gov);
                }

                _db.UpdateObject(dto);
                _db.SaveChanges(System.Data.Services.Client.SaveChangesOptions.ReplaceOnUpdate);
            }

            o.GovernorId = o.Governor.Id;
        }
Esempio n. 8
0
 public HttpResponseMessage Put([FromODataUri] Guid key, AssetValue val)
 {
     _rep.Update(val);
     return Request.CreateResponse(HttpStatusCode.NoContent);
 }
Esempio n. 9
0
 public override BaseModel ShallowCopy()
 {
     var ret = new AssetValue();
     ret.Id = this.Id;
     ret.TakingDate = this.TakingDate;
     ret.Value = this.Value;
     ret.CashFlow = this.CashFlow;
     ret.InsuranceTypeValue = this.InsuranceTypeValue;
     ret.GovernorId = this.GovernorId;
     ret.Governor = this.Governor;
     return ret;
 }