Ejemplo n.º 1
0
        private static ServiceResponse <List <ContainerSkinny> > GetContainers()
        {
            ServiceResponse <List <ContainerSkinny> > respConsSkinny = new ServiceResponse <List <ContainerSkinny> >();

            respConsSkinny.Data    = SpoonDataWorker.GetAllContainers();
            respConsSkinny.Message = "Success";
            respConsSkinny.Success = true;

            return(respConsSkinny);
        }
Ejemplo n.º 2
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);
                    }
                }

                SpoonDataWorker.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.º 3
0
        private static ServiceResponse <string> SaveContentItem(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 contentString;
                using (StreamReader reader = new StreamReader(context.Request.Body))
                {
                    contentString = reader.ReadToEnd();
                }

                ContentItem postedContent = JsonConvert.DeserializeObject <ContentItem>(contentString, settings);

                Container con = SpoonDataWorker.GetContainer(id);

                string itemKey = con.Items.FirstOrDefault(x => x.Value.Id == postedContent.Id).Key; //See if exists
                if (!string.IsNullOrEmpty(itemKey))
                {
                    con.RemoveItem(itemKey); // just remove the esisting item we are replacing.
                }

                con.AddItem(postedContent);

                SpoonDataWorker.UpdateContainer(con);

                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.º 4
0
        private static ServiceResponse <string> DeleteContainer(HttpContext context)
        {
            ServiceResponse <string> respDelete = new ServiceResponse <string>();
            string conName = context.Request.Query["name"];

            if (!String.IsNullOrEmpty(conName))
            {
                SpoonDataWorker.DeleteContainer(conName);

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

            return(respDelete);
        }
Ejemplo n.º 5
0
        private static ServiceResponse <string> EditContainerName(HttpContext context)
        {
            ServiceResponse <string> respEditName = new ServiceResponse <string>();
            string conName = context.Request.Query["name"];
            int    conId;

            if (int.TryParse(context.Request.Query["id"], out conId) && !String.IsNullOrEmpty(conName))
            {
                SpoonDataWorker.UpdateContainerName(conId, conName);

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

            return(respEditName);
        }
Ejemplo n.º 6
0
        private static ServiceResponse <Container> GetContainer(HttpContext context)
        {
            ServiceResponse <Container> respCon = new ServiceResponse <Container>();
            int       id;
            Container retVal = null;

            if (int.TryParse(context.Request.Query["id"], out id))
            {
                retVal = SpoonDataWorker.GetContainer(id);

                respCon.Data    = retVal;
                respCon.Message = "Success";
                respCon.Success = true;
            }
            else
            {
                respCon.Data    = null;
                respCon.Message = "Id not valid";
                respCon.Success = false;
            }

            return(respCon);
        }