public void SingleResource_Verify_CanCreate()
        {
            var request = new SDataSingleResourceRequest(_service)
            {
                ResourceKind = "employees"
            };

            var payload = new SDataPayload();

            payload.Values["Title"]            = "create 1";
            payload.Values["NationalIdNumber"] = "44444";
            payload.Values["LoginId"]          = "create 4";
            payload.Values["ContactId"]        = "9999";
            payload.Values["BirthDate"]        = SyndicationDateTimeUtility.ToRfc3339DateTime(new DateTime(1970, 8, 2));
            payload.Values["HireDate"]         = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now);
            payload.Values["ModifiedDate"]     = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now);
            payload.Values["MaritalStatus"]    = "Single";
            payload.Values["SalariedFlag"]     = XmlConvert.ToString(true);
            payload.Values["CurrentFlag"]      = XmlConvert.ToString(true);
            payload.Values["Gender"]           = "Male";
            payload.Values["RowGuid"]          = Guid.NewGuid().ToString();

            var entry = new AtomEntry
            {
                UpdatedOn   = DateTime.Now,
                PublishedOn = DateTime.Now
            };

            entry.SetSDataPayload(payload);
            request.Entry = entry;
            _mock.Setup(s => s.CreateEntry(request, request.Entry)).Returns(TestData.Entry);

            entry = request.Create();
            Expect(entry, Is.Not.Null);
        }
        public bool InsertRecord <T>(T dataItem)
        {
            bool returnData = false;

            // Create a SData serivce object connection.  Use the proper url and login info.
            ISDataService svc = new SDataService(GetFullSDataUrl(), _userId, _password);

            // Create the SData Payload of data to be sent
            SDataPayload myPayload = new SDataPayload();

            myPayload.Namespace    = string.Empty;
            myPayload.ResourceName = typeof(T).Name;
            myPayload.Uri          = new Uri(svc.Url);

            // Add to an ATOM feed entry b/c that's what SData uses
            AtomEntry myEntry = new AtomEntry();

            myEntry.SetSDataPayload(myPayload);

            // loop through the properties to find matching data from our query
            foreach (PropertyInfo property in dataItem.GetType().GetProperties())
            {
                // If the property value is null, don't add it
                if (property.GetValue(dataItem) == null)
                {
                    continue;
                }

                myPayload.Values.Add(property.Name, property.GetValue(dataItem));
            }

            // prepare the create request
            SDataSingleResourceRequest sendRequest = new SDataSingleResourceRequest(svc, myEntry);

            sendRequest.ResourceKind     = typeof(T).Name;
            sendRequest.ResourceSelector = "";

            try
            {
                AtomEntry response = sendRequest.Create();
                returnData = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                returnData = false;
            }

            return(returnData);
        }
        public bool UpdateTechnicianRecord(JT_Technician dataItem)
        {
            bool returnData = false;

            // Create a SData serivce object connection.  Use the proper url and login info.
            ISDataService svc = new SDataService(GetFullSDataUrl(), _userId, _password);

            // Create the SData Payload of data to be sent
            SDataPayload myPayload = new SDataPayload();

            myPayload.Namespace    = string.Empty;
            myPayload.ResourceName = typeof(JT_Technician).Name;
            myPayload.Uri          = new Uri(svc.Url);

            // Add to an ATOM feed entry b/c that's what SData uses
            AtomEntry myEntry = new AtomEntry();

            myEntry.SetSDataPayload(myPayload);

            // update only specific properties
            myPayload.Values.Add("CurrentStartTime", dataItem.CurrentStartTime);
            myPayload.Values.Add("CurrentStartDate", dataItem.CurrentStartDate.ToString("yyyy-MM-dd"));
            myPayload.Values.Add("CurrentSalesOrderNo", dataItem.CurrentSalesOrderNo);
            myPayload.Values.Add("CurrentWTNumber", dataItem.CurrentWTNumber);
            myPayload.Values.Add("CurrentWTStep", dataItem.CurrentWTStep);
            myPayload.Values.Add("CurrentStatus", dataItem.CurrentStatus);

            // prepare the create request
            SDataSingleResourceRequest sendRequest = new SDataSingleResourceRequest(svc, myEntry);

            sendRequest.ResourceKind     = typeof(JT_Technician).Name;
            sendRequest.ResourceSelector = dataItem.TechnicianDeptNo + ";" + dataItem.TechnicianNo;

            try
            {
                AtomEntry response = sendRequest.Update();
                returnData = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                returnData = false;
            }

            return(returnData);
        }
示例#4
0
        AtomEntry CopyEntityToAtomEntry(IPersistentEntity entity)
        {
            var entry   = new AtomEntry();
            var payload = new SDataPayload();

            payload.ResourceName = typeof(TEntity).Name.Substring(1);
            payload.Namespace    = "http://schemas.sage.com/dynamic/2007";

            foreach (var prop in typeof(TEntity).GetProperties())
            {
                if (!prop.PropertyType.FullName.StartsWith("Sage.Entity.Interfaces") &&
                    !prop.PropertyType.FullName.StartsWith("ICollection") &&
                    prop.CanWrite)
                {
                    payload.Values[prop.Name] = prop.GetValue(entity, null);
                }
            }
            entry.SetSDataPayload(payload);

            return(entry);
        }