示例#1
0
        public HttpResponseMessage SaveInstrumentAccuracyCheck(JObject jsonData)
        {
            var     db   = ServicesContext.Current;
            dynamic json = jsonData;
            User    me   = AuthorizationManager.getCurrentUser();

            Instrument instrument = db.Instruments.Find(json.InstrumentId.ToObject <int>());

            if (instrument == null)
            {
                throw new System.Exception("Configuration error.  Please try again.");
            }

            InstrumentAccuracyCheck ac = json.AccuracyCheck.ToObject <InstrumentAccuracyCheck>();

            ac.UserId = me.Id;

            if (ac.Id == 0)
            {
                instrument.AccuracyChecks.Add(ac);
                db.SaveChanges();
            }
            else
            {
                db.Entry(ac).State = EntityState.Modified;
                db.SaveChanges();
            }

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, ac);

            return(response);
        }
示例#2
0
        public HttpResponseMessage RemoveInstrumentAccuracyCheck(JObject jsonData)
        {
            var     db   = ServicesContext.Current;
            dynamic json = jsonData;
            User    me   = AuthorizationManager.getCurrentUser();

            Instrument instrument = db.Instruments.Find(json.InstrumentId.ToObject <int>());

            if (instrument == null)
            {
                throw new System.Exception("Configuration error.  Please try again.");
            }

            InstrumentAccuracyCheck ac = db.AccuracyChecks.Find(json.AccuracyCheck.Id.ToObject <int>());

            if (ac == null)
            {
                throw new System.Exception("Configuration error.  Please try again.");
            }

            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServicesContext"].ConnectionString))
            {
                con.Open();

                var query = "DELETE FROM InstrumentAccuracyChecks WHERE Id  = " + ac.Id;
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    logger.Debug(query);
                    cmd.ExecuteNonQuery();
                }

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
        }