Ejemplo n.º 1
0
        public UpdateProjectResponse UpdateProject(string projectId, ProjectDTO projectDTO)
        {
            UpdateProjectResponse projectResponse = new UpdateProjectResponse(false, projectId);
            XDocument             xDoc            = new XDocument();

            try
            {
                // get XML based on ProjectDTO object
                using (var writer = xDoc.CreateWriter())
                {
                    var serializer = new DataContractSerializer(projectDTO.GetType());
                    serializer.WriteObject(writer, projectDTO);
                }

                // send the project to DB
                new ProjectDB(Utility.ConfigurationHelper.GPD_Connection).UpdateProject(projectId, xDoc);

                // project updated successful
                projectResponse.Status = true;
            }
            catch (Exception ex)
            {
                log.Error("Unable to update the project", ex);
                projectResponse.Message = "Unable to update the project";
            }

            return(projectResponse);
        }
Ejemplo n.º 2
0
        public AddProjectResponse AddProject(string partnerName, int userId, ProjectDTO projectDTO)
        {
            AddProjectResponse responseDTO = new AddProjectResponse();
            XDocument          xDoc        = new XDocument();

            try
            {
                // set project ID
                string projectId = System.Guid.NewGuid().ToString();

                // get XML based on ProjectDTO object
                using (var writer = xDoc.CreateWriter())
                {
                    var serializer = new DataContractSerializer(projectDTO.GetType());
                    serializer.WriteObject(writer, projectDTO);
                }

                xDoc.Root.XPathSelectElements("//*[local-name()='items']/*[local-name()='item']")
                .ToList()
                .ForEach(T => T.Add(new XAttribute("guid", System.Guid.NewGuid().ToString())));

                Dictionary <string, string> categoriesList =
                    xDoc.Root.XPathSelectElements("//*[local-name()='items']/*[local-name()='item']/*[local-name()='categories']/*[local-name()='category']")
                    .ToList()
                    .GroupBy(g => g.XPathSelectElement("*[local-name()='taxonomy']").Value + "::" + g.XPathSelectElement("*[local-name()='title']").Value)
                    .ToDictionary(g => g.Key, g => System.Guid.NewGuid().ToString());

                xDoc.Root.XPathSelectElements("//*[local-name()='items']/*[local-name()='item']/*[local-name()='categories']/*[local-name()='category']")
                .ToList()
                .ForEach(T => T.Add(new XAttribute("guid", categoriesList[
                                                       T.XPathSelectElement("*[local-name()='taxonomy']").Value + "::" + T.XPathSelectElement("*[local-name()='title']").Value
                                                   ])));

                // send the project to DB
                new ProjectDB(Utility.ConfigurationHelper.GPD_Connection).AddProject(partnerName, userId, projectId, xDoc);

                // project content inserted successful
                responseDTO = new AddProjectResponse(true, projectId);
            }
            catch (Exception ex)
            {
                log.Error("Unable to add project", ex);
                responseDTO = new AddProjectResponse();
            }

            return(responseDTO);
        }