コード例 #1
0
        public async Task<IHttpActionResult> PostEnteredChart(EnteredChart enteredChart)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            this.db.EnteredCharts.Add(enteredChart);
            await this.db.SaveChangesAsync();

            return this.CreatedAtRoute("DefaultApi", new { id = enteredChart.EnteredChartId }, enteredChart);
        }
コード例 #2
0
        public async Task<IHttpActionResult> PutEnteredChart(int id, EnteredChart enteredChart)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            if (id != enteredChart.EnteredChartId)
            {
                return this.BadRequest();
            }

            this.db.Entry(enteredChart).State = EntityState.Modified;

            try
            {
                await this.db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!this.EnteredChartExists(id))
                {
                    return this.NotFound();
                }
                else
                {
                    throw;
                }
            }

            return this.StatusCode(HttpStatusCode.NoContent);
        }
コード例 #3
0
        public JsonResult CreateNewEnteredChart(
            [NotNull] string subjectName,
            [NotNull] string subjectLocation,
            DateTime originDateTime,
            bool originDateTimeUnknown,
            byte chartTypeId)
        {
            if (subjectName == null)
            {
                throw new ArgumentNullException("subjectName");
            }

            if (subjectLocation == null)
            {
                throw new ArgumentNullException("subjectLocation");
            }

            try
            {
                var enteredChart = new EnteredChart
                                       {
                                           SubjectName = subjectName,
                                           SubjectLocation = subjectLocation,
                                           OriginDateTime = originDateTime,
                                           OriginDateTimeUnknown = originDateTimeUnknown,
                                           ChartTypeId = chartTypeId,
                                       };

                this.db.EnteredCharts.Add(enteredChart);
                this.db.SaveChanges();

                return this.Json("Success", JsonRequestBehavior.DenyGet);
            }
            catch (Exception ex)
            {
                return this.Json("Failed: " + ex.Message, JsonRequestBehavior.DenyGet);
            }
        }