public IHttpActionResult Add(TradeBindingModel tradeModel) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } if (tradeModel == null) { return(this.BadRequest("Invalid input parameters.")); } var trade = new Trade(); trade.Name = tradeModel.Name; trade.Position = tradeModel.Position; try { this.Data.Trades.Add(trade); this.Data.SaveChanges(); } catch (Exception ex) { return(this.GetExceptionMessage(ex)); } return(this.Ok(string.Format("Trade name: {0} and id: {1} is created", trade.Name, trade.Id))); }
public IHttpActionResult Edit(int id, TradeBindingModel tradeModel) { if (!this.ModelState.IsValid) { return(this.BadRequest(ModelState)); } if (tradeModel == null) { return(this.BadRequest("Invalid input parameters.")); } var trade = this.Data.Trades.All() .Where(x => x.Id == id) .FirstOrDefault(); this.CheckObjectForNull(trade, "trade", id); trade.Name = tradeModel.Name; trade.Position = tradeModel.Position; this.Data.Trades.Update(trade); try { this.Data.SaveChanges(); } catch (Exception ex) { return(this.GetExceptionMessage(ex)); } return(Ok(string.Format("Trade with id {0} is changed successfully", id))); }