Exemple #1
0
        public HttpResponseMessage CreateType(WebApplication2.Models.Type type)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                db.Type.Add(type);
                db.SaveChanges();
                response.Content = new StringContent("{Id:" + type.TypeId + ",Name:" + type.Name
                                                     + ",Model" + type.Model + "}", System.Text.Encoding.UTF8, "appllication/json");
            }
            catch (Exception ex)
            {
                response.Content = new StringContent("{Error:" + ex.Message + "}", System.Text.Encoding.UTF8, "application/json")
                ;
            }

            return(response);
        }
Exemple #2
0
        public HttpResponseMessage DeleteType(WebApplication2.Models.Type type)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);
            var t        = (from tp in db.Type where tp.TypeId == type.TypeId select tp).First();

            try
            {
                db.Type.Remove(t);
                db.SaveChanges();
                response.Content = new StringContent("{Id:" + type.TypeId + ",Name:" + type.Name
                                                     + ",Model" + type.Model + "}", System.Text.Encoding.UTF8, "appllication/json");
            }
            catch (Exception ex)
            {
                response.Content = new StringContent("{Error:" + ex.Message + "}", System.Text.Encoding.UTF8, "application/json")
                ;
            }

            return(response);
        }