public IHttpActionResult PutCalcHistory(int id, CalcHistory calcHistory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            calcHistory.UpdateDate      = DateTime.Now;
            db.Entry(calcHistory).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CalcHistoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PostCalcHistory(CalcHistory calcHistory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            calcHistory.UpdateDate = DateTime.Now;
            db.CalcHistory.Add(calcHistory);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = calcHistory.ID }, calcHistory));
        }
        public IHttpActionResult DeleteCalcHistory(int id)
        {
            CalcHistory calcHistory = db.CalcHistory.Find(id);

            if (calcHistory == null)
            {
                return(NotFound());
            }

            db.CalcHistory.Remove(calcHistory);
            db.SaveChanges();

            return(Ok(calcHistory));
        }
 public IHttpActionResult GetCalcHistory(int id, bool SelectList)
 {
     if (SelectList == true)
     {
         var List = db.CalcHistory.Where(i => i.CalcID == id);
         return(Ok(List));
     }
     else
     {
         CalcHistory calcHistory = db.CalcHistory.Find(id);
         if (calcHistory == null)
         {
             return(NotFound());
         }
         return(Ok(calcHistory));
     }
 }
        public async Task <ActionResult <CalcHistory> > CalculateFromText(CalcHistory calcHistory)
        {
            calcHistory.SourceIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
            calcHistory.CalcTime        = DateTime.Now;
            DataTable dt = new DataTable();

            try
            {
                var y = dt.Compute(calcHistory.CalcText, "");
                calcHistory.CalcTextAnswer = y.ToString();
            }
            catch
            {
                calcHistory.CalcTextAnswer = "Failed to evaluate the calculation!";
            }
            _context.CalcHistories.Add(calcHistory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCalcHistory", new { id = calcHistory.CalcHistoryId }, calcHistory));
        }