Ejemplo n.º 1
0
        private static ServiceResponse <string> SaveContainer(HttpContext context)
        {
            ServiceResponse <string> respSave = new ServiceResponse <string>();
            int id;
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.ObjectCreationHandling = ObjectCreationHandling.Replace;

            if (int.TryParse(context.Request.Query["id"], out id))
            {
                string containerString;
                using (StreamReader reader = new StreamReader(context.Request.Body))
                {
                    containerString = reader.ReadToEnd();
                }

                Container postedCon = JsonConvert.DeserializeObject <Container>(containerString, settings);

                //Do a quick check to make sure any newly generated GUIDs are unique and there was no funny business on the client side
                List <Guid> guids = new List <Guid>();
                foreach (KeyValuePair <string, ContentItem> item in postedCon.Items)
                {
                    if (!guids.Contains(item.Value.Id))
                    {
                        guids.Add(item.Value.Id);
                    }
                    else
                    {
                        item.Value.Id = Guid.NewGuid();
                        guids.Add(item.Value.Id);
                    }
                }

                SpoonData.UpdateContainer(postedCon);

                respSave.Data    = "Success";
                respSave.Message = "Success";
                respSave.Success = true;
            }
            else
            {
                respSave.Data    = "Failure";
                respSave.Message = "Id not valid";
                respSave.Success = false;
            }

            return(respSave);
        }
Ejemplo n.º 2
0
 public static void UpdateContainer(Container con)
 {
     data.UpdateContainer(con);
 }