public TradeView Convert(Trade trade, string lang) { SkuView relatedSku = new SkuViewController().Get(trade.SkuGuid, lang); OrderView orderView = new OrderViewController().Get(trade.OrderGuid, lang); return(new TradeView { Guid = trade.Guid, TradeCode = trade.TradeCode, BuyerGuid = trade.BuyerGuid, BuyerUserName = trade.BuyerUserName, BuyerLanguageCode = trade.BuyerLanguageCode, BuyerPhoneNumber = trade.BuyerPhoneNumber, SellerGuid = trade.SellerGuid, SellerLanguageCode = trade.SellerLanguageCode, SellerUserName = trade.SellerUserName, SellerPhoneNumber = trade.SellerPhoneNumber, Created = trade.Created, Currency = trade.Currency, OrderGuid = trade.OrderGuid, ProductColourGuid = orderView.ProductColourGuid, ProductColourName = orderView.ProductColourName, ProductCondition = orderView.ProductCondition, ProductConditionName = orderView.ProductConditionName, Price = trade.Price, LastModified = trade.LastModified, Status = trade.Status, Quantity = trade.Quantity, SkuGuid = trade.SkuGuid, SkuFullName = relatedSku.FullName, Total = trade.Total }); }
public TradeOfferView Get(Guid tradeOfferGuid, string lang = "en-US") { //you can only view if you are the to party Account account = AccountController.GetAccountByUsername(User.Identity.Name); using (DatabaseContext context = new DatabaseContext()) { var offer = (from o in context.TradeOffers where o.Guid == tradeOfferGuid select o).FirstOrDefault(); if (offer == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (offer.ToAccountGuid != account.Guid && offer.FromAccountGuid != account.Guid) { throw new HttpResponseException(HttpStatusCode.Forbidden); } OrderView orderView = new OrderViewController().Get(offer.OrderGuid, lang); SkuView relatedSku = new SkuViewController().Get(orderView.SkuGuid, lang); Account from = (from a in context.Accounts where a.Guid == offer.FromAccountGuid select a).First(); Account to = (from a in context.Accounts where a.Guid == offer.ToAccountGuid select a).First(); TradeOfferView converted = new TradeOfferView { Guid = offer.Guid, Created = offer.Created, Currency = offer.Currency, FromAccountGuid = offer.FromAccountGuid, LastModified = offer.LastModified, OrderGuid = offer.OrderGuid, Price = offer.Price, ProductColourGuid = orderView.ProductColourGuid, ProductColourName = orderView.ProductColourName, ProductCondition = orderView.ProductCondition, ProductConditionName = orderView.ProductConditionName, Location = orderView.Location, LocationName = orderView.LocationName, Quantity = offer.Quantity, SkuGuid = orderView.SkuGuid, SkuImageUrl = orderView.ImageSrc, SkuFullName = orderView.SkuFullName, Total = offer.Quantity * offer.Price, TradeCode = offer.TradeCode, Type = orderView.Type, FromUserName = from.Username, ToAccountGuid = offer.ToAccountGuid, ToUserName = to.Username, CancelReason = offer.CancelReason, Status = GetStatus(offer), Deadline = offer.Deadline }; return(converted); } }