Exemple #1
0
        public ActionResult Delete(string id)
        {
            //Validate/initialize input parameters
            string requestId = id;

            if (String.IsNullOrWhiteSpace(requestId))
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, "Invalid parameter(s)"));
            }

            //Delete input values from database, if indicated...
            ExportTaskData etd = _hcDbContext.ExportTaskDataSet.SingleOrDefault(e => e.RequestId.Equals(id));

            if (null == etd)
            {
                //Not found - return error...
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "Requested task not found"));
            }
            else
            {
                //Found - delete the row...
                _hcDbContext.ExportTaskDataSet.Remove(etd);
                _hcDbContext.SaveChanges();
            }

            //Success - convert input data to JSON and return (so to avoid a parsing error on the client...)
            // Source: http://stackoverflow.com/questions/25173727/syntax-error-unexpected-end-of-input-parsejson
            var responseData = new { requestId = id };
            var json         = JsonConvert.SerializeObject(responseData);

            Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
            return(Json(json, "application/json"));
        }
        public ActionResult Post(UserTimeSeries userTimeSeries)
        {
            //Validate/initialize input parameters
            if (null == userTimeSeries)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, "Invalid parameter(s)"));
            }

            //Check time stamp values - if DateTime.MinValue change to SQL Server minimum value to avoid a 'value out of range' error...
            foreach (var timeSeries in userTimeSeries.TimeSeries)
            {
                if (DateTime.MinValue == timeSeries.WaterOneFlowTimeStamp)
                {
                    timeSeries.WaterOneFlowTimeStamp = new DateTime(1753, 1, 1);
                }
            }

            //Load input values to database
            UserTimeSeries uts = _hcDbContext.UserTimeSeriesSet.SingleOrDefault(u => u.UserEmail.Equals(userTimeSeries.UserEmail));

            if (null == uts)
            {
                //New entry - save
                _hcDbContext.UserTimeSeriesSet.Add(userTimeSeries);
                _hcDbContext.SaveChanges();
            }
            else
            {
                //Existing entry - save time series only...
                _hcDbContext.DM_TimeSeriesSet.AddRange(userTimeSeries.TimeSeries);
                _hcDbContext.SaveChanges();
            }

            //Success - convert input data to JSON and return (so to avoid a parsing error on the client...)
            // Source: http://stackoverflow.com/questions/25173727/syntax-error-unexpected-end-of-input-parsejson
            var json = JsonConvert.SerializeObject(userTimeSeries);

            Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
            return(Json(json, "application/json"));
        }