Exemple #1
0
        public void RetrieveAll_QueryExpression_Typed()
        {
            //Arrange
            int    totalRecords        = 5010;
            string distinctAccountName = Guid.NewGuid().ToString();

            List <Entity> accounts = new List <Entity>();

            for (int i = 0; i < totalRecords; i++)
            {
                accounts.Add(new Account()
                {
                    Id   = Guid.NewGuid(),
                    Name = distinctAccountName
                });
            }
            _context.Initialize(accounts);

            //Act
            Microsoft.Xrm.Sdk.Query.QueryExpression queryExpression = new Microsoft.Xrm.Sdk.Query.QueryExpression(Account.EntityLogicalName)
            {
                ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(Account.Fields.Name)
            };
            queryExpression.Criteria.AddCondition(Account.Fields.Name, Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal, distinctAccountName);

            IEnumerable <Account> results = _service.RetrieveAll <Account>(queryExpression);

            //Assert
            Assert.Equal(totalRecords, results.Count());
        }
        public JsonResult Authenticate(dynamic data)
        {
            log.Info("Entering Authenticate method");
            var result = new JsonResult();

            result.Data = "false";
            Microsoft.Xrm.Sdk.Query.QueryExpression queryExpression = new Microsoft.Xrm.Sdk.Query.QueryExpression("contact")
            {
                Distinct = true,
                Criteria = new FilterExpression(LogicalOperator.And)
                {
                    Conditions =
                    {
                        new ConditionExpression("emailaddress1",   ConditionOperator.Equal, data.username.Value),
                        new ConditionExpression("concap_password", ConditionOperator.Equal, data.password.Value)
                    }
                },
                ColumnSet = new ColumnSet(new string[] { "contactid", "fullname", "concap_password" })
            };

            try
            {
                log.Info("Data Retrieval from MSCRM begin");
                EntityCollection contacts = _serviceProxy.RetrieveMultiple(queryExpression);
                log.Debug("Retrieved record count =" + contacts.Entities.Count);
                if (contacts.Entities.Count > 0)
                {
                    Entity contact = contacts.Entities[0];
                    if (contact.GetAttributeValue <String>("concap_password").Equals(data.password.Value))
                    {
                        log.Debug("User logged in : " + contacts.Entities[0].Id);
                        result.Data = contacts.Entities[0];
                    }
                    else
                    {
                        result.Data = null;
                    }
                }
                //                    result.Data = "true";

                else
                {
                    result.Data = null;
                    //                    result.Data = "false";
                }
                log.Info("Data Retrieval from MSCRM end");
            }
            catch (Exception ex)
            {
                log.Error(" Exception occured in Authenticate method ." + ex.Message + ". Returning null");
                return(new JsonResult
                {
                    Data = null
                });
            }
            log.Info("leaving Authenticate method");
            return(result);
        }