示例#1
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);
        }
示例#2
0
 public JsonResult AddedProjectDetails(AddProject prtdetails)
 {
     try
     {
         AddProjectResponse result = null;
         if (prtdetails != null)
         {
             result = CABusinessProjectTrackingAPIClient.GetHttpResponse <AddProjectResponse>(prtdetails, CABPTMethodConstants.ADDNEWPROJECT);
         }
         return(Json(JsonConvert.SerializeObject(result), JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         JsonExceptionResult jsonexc = new JsonExceptionResult();
         return(Json(JsonConvert.SerializeObject(new CABPTException(ex, out jsonexc))));
     }
 }