コード例 #1
0
        public void AdicionarTarefa_ListASMX()
        {
            Tarefa tarefa = new Tarefa();
            string titulo = "Tarefa Gerada no Teste";
            tarefa.Titulo = titulo;
            tarefa.PercentComplete = "0";
            tarefa.Priority = "0";
            tarefa.StartDate = DateTime.Now;
            tarefa.DueDate = DateTime.Now.AddDays(5);

            int totalAnterior = Repositorio.ObterTodos().Count;
            Tarefa tarefaRetorno = Repositorio.Salvar(tarefa);
            int totalDepois = Repositorio.ObterTodos().Count;

            Assert.IsNotNull(tarefa);
            Assert.AreEqual(titulo, tarefa.Titulo);
            Assert.AreEqual(totalAnterior + 1, totalDepois);
        }
コード例 #2
0
        public static Tarefa ItemParaTarefa(XmlNode item)
        {
            Tarefa tarefa = new Tarefa();

            tarefa.ID = int.Parse(item.Attributes["ows_ID"].Value);
            tarefa.Titulo = item.Attributes["ows_Title"].Value;

            if (item.Attributes["ows_PercentComplete"] != null)
                tarefa.PercentComplete = item.Attributes["ows_PercentComplete"].Value;

            // if (item["AssignetTo"] != null)
            //     tarefa.AssignetTo = item["AssignetTo"].ToString();

            DateTime dataSaida;

            if (item.Attributes["ows_DueDate"] != null && DateTime.TryParse(item.Attributes["ows_DueDate"].Value, out dataSaida))
            {
                tarefa.DueDate = dataSaida;
            }

            if (item.Attributes["ows_StartDate"] != null && DateTime.TryParse(item.Attributes["ows_StartDate"].Value, out dataSaida))
            {
                tarefa.StartDate = dataSaida;
            }

            if (item.Attributes["ows_Body"] != null)
                tarefa.Body = item.Attributes["ows_Body"].Value;

            // tarefa.TaskGroup = item["TaskGroup"].ToString();
            tarefa.Predecessors = item.Attributes["ows_Predecessors"].Value;
            tarefa.Priority = item.Attributes["ows_Priority"].Value;

            if (item.Attributes["ows_Status"] != null)
                tarefa.Status = item.Attributes["ows_Status"].Value;

            //tarefa.Author = new Usuario(item["Author"] as FieldUserValue);
            //tarefa.Editor = new Usuario(item["Editor"] as FieldUserValue);

            return tarefa;
        }
コード例 #3
0
        public static String TarefaParaXML(Tarefa tarefa)
        {
            StringBuilder xml = new StringBuilder();

            if (tarefa.ID == 0)
            {
                xml.Append("<Method ID = '0' Cmd='New'>");
            }
            else
            {
                xml.Append("<Method ID = '0' Cmd='Update'>");
                xml.Append("<Field Name='ID'>"+ tarefa.ID.ToString() +"</Field>");
            }

            xml.Append("<Field Name='Title'>" + tarefa.Titulo + "</Field>");
            xml.Append("</Method>");

            //"<Method ID='1' Cmd='Update'><Field Name='ID'>6</Field><Field Name='Title'>Modified sixth item</Field></Method>" +
            //"<Method ID='2' Cmd='Update'><Field Name='ID'>7</Field><Field Name='Title'>Modified seventh item</Field></Method>" +
            //"<Method ID='3' Cmd='Delete'><Field Name='ID'>5</Field></Method>" +
            //"<Method ID='4' Cmd='New'><Field Name='Title'>" + tarefa.Titulo + "</Field></Method>";

            //item["Title"] = tarefa.Titulo;
            //item["PercentComplete"] = tarefa.PercentComplete;
            //// if (item["AssignetTo"] != null)
            ////     tarefa.AssignetTo = item["AssignetTo"].ToString();
            //item["StartDate"] = tarefa.StartDate;
            //item["DueDate"] = tarefa.DueDate;
            //item["Body"] = tarefa.Body;
            //// tarefa.TaskGroup = item["TaskGroup"].ToString();
            //item["Predecessors"] = tarefa.Predecessors;
            //item["Priority"] = tarefa.Priority;
            //item["Status"] = tarefa.Status;
            //item["Author"] = tarefa.Author;
            //item["Editor"] = tarefa.Editor;

            return xml.ToString();
        }
コード例 #4
0
        public Tarefa Salvar(Tarefa tarefa)
        {
            ///*Get Name attribute values (GUIDs) for list and view. */
            System.Xml.XmlNode ndListView = Contexto.GetListAndView("Tarefas", "");
            string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
            string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;

            /*Create an XmlDocument object and construct a Batch element and its
            attributes. Note that an empty ViewName parameter causes the method to use the default view. */
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
            batchElement.SetAttribute("OnError", "Continue");
            batchElement.SetAttribute("ListVersion", "1");
            batchElement.SetAttribute("ViewName", strViewID);

            /*Specify methods for the batch post using CAML. To update or delete,
            specify the ID of the item, and to update or add, specify
            the value to place in the specified column.*/
            batchElement.InnerXml = TarefaConverterHelper.TarefaParaXML(tarefa);

            /*Update list items. This example uses the list GUID, which is recommended,
            but the list display name will also work.*/
            Contexto.UpdateListItems(strListID, batchElement);

            return tarefa;
        }