public IHttpActionResult PutCommodity(Guid id, Commodity commodity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != commodity.Id) { return(BadRequest()); } db.Entry(commodity).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CommodityExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutTrade(Guid id, Trade trade) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != trade.Id) { return(BadRequest()); } db.Entry(trade).State = EntityState.Modified; try { trade.Price = db.Commodities.Find(trade.CommodityId).CurrentPrice; db.SaveChanges(); businessLayer.UpdateNotification((trade)); } catch (DbUpdateConcurrencyException) { if (!TradeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); } //Update a trade
public void ChangePrice(Trade trade, TypeOfFunction type) //Change price after trade management { Commodity commodity = context.Commodities.Find(trade.CommodityId); double priceVariation = ((commodity.CurrentPrice * trade.Quantity) / (commodity.BasePrice * 100)); if (trade.Side == Side.Buy) { if (type == TypeOfFunction.Add) { commodity.CurrentPrice += priceVariation; } else if (type == TypeOfFunction.Delete) { if (priceVariation > commodity.CurrentPrice) { commodity.CurrentPrice = 0; } else { commodity.CurrentPrice -= priceVariation; } } else { commodity.CurrentPrice += priceVariation; } } else { if (type == TypeOfFunction.Add) { if (priceVariation > commodity.CurrentPrice) { commodity.CurrentPrice = 0; } else { commodity.CurrentPrice -= priceVariation; } } else if (type == TypeOfFunction.Delete) { commodity.CurrentPrice += priceVariation; } else { if (priceVariation > commodity.CurrentPrice) { commodity.CurrentPrice = 0; } else { commodity.CurrentPrice -= priceVariation; } } } UpdateTickerNotification(commodity); context.SaveChanges(); }
public IHttpActionResult PostUser(User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { db.Users.Add(user); db.SaveChanges(); } catch (Exception e) { return(BadRequest(e.ToString())); } return(CreatedAtRoute("DefaultApi", new { id = user.Id }, user)); } //User Login