public async Task<IHttpActionResult> PutForm(Guid id, Form form)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != form.CrmFormId)
            {
                return BadRequest();
            }

            db.Entry(form).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FormExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 public Form Add(Form item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
   //  item.Id = Guid.NewGuid();
   //  forms.Add(item);
     db.Set<Form>().Add(item);
     db.SaveChanges();
     return item;
 }
 public bool Update(Form item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     int index = forms.FindIndex(p => p.CrmFormId == item.CrmFormId);
     if (index == -1)
     {
         return false;
     }
     forms.RemoveAt(index);
     forms.Add(item);
     return true;
 }
Example #4
0
        public List<FormField> getFormFields(string formName)
        {
            //RetrieveEntityRequest retrieveFormEntityRequest = new RetrieveEntityRequest
            //{
            //    EntityFilters = EntityFilters.Attributes,
            //    LogicalName = formName
            //};
           
            //RetrieveEntityResponse retrieveFormEntityResponse = (RetrieveEntityResponse)_service.Execute(retrieveFormEntityRequest);

            // string entityname = retrieveBankAccountEntityResponse.EntityMetadata.ManyToManyRelationships[0].IntersectEntityName;
            //var test1 = new List<string>();
            List<string> test1 = new List<string>();
            //var test = retrieveFormEntityResponse.EntityMetadata.Attributes.ToArray();
            //test.ToList().ForEach(i => test1.Add(i.LogicalName.ToString()));
            QueryExpression qe = new QueryExpression("systemform");
            qe.Criteria.AddCondition("type", ConditionOperator.Equal, 2); //main form
            qe.Criteria.AddCondition("objecttypecode", ConditionOperator.Equal, "contact");
            qe.ColumnSet.AddColumn("formxml");

          
          //  var test2 = _service.RetrieveMultiple(qe).Entities.ToArray();
          //  test2.ToList().ForEach(y => test3.Add(y.Attributes["formxml"].ToString()));

            string frmXml = _service.RetrieveMultiple(qe).Entities.First().Attributes["formxml"].ToString();

          //  StringBuilder output = new StringBuilder();

            XElement root = XElement.Parse(frmXml);

            List<FormField> controls = new List<FormField>();
            var query = root.Descendants("tabs")    
               .Concat(root.Descendants("control"))
               .Select(x => new {
                   control = (string)x.Attribute("datafieldname"),
                   id = (string)x.Attribute("id")         
               });
            Debug.WriteLine(query.Count());
            // test4.Add((string)el.Attribute("tab"));
            Form form = new Form
            {
                CrmFormName = formName,
            };

          
            foreach (var c in query)
            {
                FormField ff = new FormField
                {         
                    CrmfieldId = c.id,
                    CrmfieldName = c.control              
                   // form = form                    
                };
                controls.Add(ff);               
            }

            // OutputTextBlock.Text = output.ToString();

            return controls;
           // return frmXml;
        }
        public async Task<IHttpActionResult> PostForm(Form form)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            form.CrmFormId = Guid.NewGuid();
            form.CreatedOn = DateTime.Now;
            form.UpdatedOn = DateTime.Now;
            db.Forms.Add(form);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (FormExists(form.CrmFormId))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = form.CrmFormId }, form);
        }