public async Task <IHttpActionResult> PutEsiCategory(decimal id, EsiCategory esiCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != esiCategory.CateID)
            {
                return(BadRequest());
            }

            db.Entry(esiCategory).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public async Task <bool> CateNew(EsiCategory objCate)
        {
            //string s = JsonConvert.SerializeObject(objCate, Formatting.Indented,
            //          new JsonSerializerSettings()
            //          {
            //              ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            //          });

            //HttpResponseMessage response
            //    = client.PostAsJsonAsync("EsiCategories", objCate).Result;


            JsonMediaTypeFormatter jsonformatter;

            jsonformatter = new JsonMediaTypeFormatter();
            jsonformatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            HttpResponseMessage response =
                client.PostAsync <EsiCategory>("EsiCategories", objCate, jsonformatter).Result;

            response.EnsureSuccessStatusCode();

            // response.EnsureSuccessStatusCode();
            //if (response.IsSuccessStatusCode)
            //{

            //}
            // return URI of the created resource.
            return(response.IsSuccessStatusCode);
        }
        public async Task <IHttpActionResult> GetEsiCategory(decimal id)
        {
            EsiCategory esiCategory = await db.EsiCategories.FindAsync(id);

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

            return(Ok(esiCategory));
        }
        public async Task <IHttpActionResult> DeleteEsiCategory(decimal id)
        {
            EsiCategory esiCategory = await db.EsiCategories.FindAsync(id);

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

            db.EsiCategories.Remove(esiCategory);
            await db.SaveChangesAsync();

            return(Ok(esiCategory));
        }
        public async Task <IHttpActionResult> PostEsiCategory(EsiCategory esiCategory)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            // product = response.Content.
            //var sssss = response.Content.ReadAsStringAsync().Result;

            //  EsiCategory  esiCategory = JsonConvert.DeserializeObject<EsiCategory>(s);
            try
            {
                //db.Entry(esiCategory.EsiFields.Select(x => x.EsiMetaType)).State = System.Data.Entity.EntityState.Unchanged;

                using (var newContext = new EME())
                {
                    newContext.Entry(esiCategory).State = esiCategory.CateID
                                                          == 0 ? EntityState.Added : EntityState.Modified;

                    foreach (EsiField filed in esiCategory.EsiFields)
                    {
                        newContext.Entry(filed).State             = filed.FieldID == 0 ? EntityState.Added : EntityState.Modified;
                        newContext.Entry(filed.EsiMetaType).State = EntityState.Unchanged;

                        //foreach (EsiMetaType meta in filed.EsiMetaType)
                        //    newContext.Entry(filed).State = filed.FieldID == 0 ? EntityState.Added : EntityState.Modified;
                    }
                    newContext.SaveChanges();
                }

                //  db.EsiCategories.Add(esiCategory);
                // await db.SaveChangesAsync();
            }
            catch (Exception e)
            {
            }

            //   db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = esiCategory.CateID }, esiCategory));
        }