public void TuplesBasicOperatorTest()
        {
            // rule DTO  #1
            var car = new CarDTO
            {
                Make = "Ford",
                Year = 2010,
                Model = "Expedition",
                AskingPrice = 10000.0000m,
                SellingPrice = 9000.0000m
            };

            // rule DTO  #2
            var salesperson = new SalesPersonDTO
            {
                State = "PA",
                IsManager = true,
                MaximumDiscount = 1000.0000m
            };

            // programatic mix in of claims rule and rule against the DTO user
            var carRule1 = new Rule("Year", "2010", "GreaterThanOrEqual","CarDTO");
            var salePersonRule1 = new Rule("State", "PA", "Equals", "SalesPersonDTO");
            var salePersonRule2 = new Rule("IsManager", "true", "Equals", "SalesPersonDTO");
            var re = new TupleRuleEngine();

            // Compile the rules as a seperate step
            Expression<Func<CarDTO, SalesPersonDTO, bool>> carRule1Expression = re.GetExpression<CarDTO, SalesPersonDTO>(carRule1);
            Expression<Func<CarDTO, SalesPersonDTO, bool>> salePersonRuleExpression1 = re.GetExpression<CarDTO, SalesPersonDTO>(salePersonRule1);
            Expression<Func<CarDTO, SalesPersonDTO, bool>> salePersonRuleExpression2 = re.GetExpression<CarDTO, SalesPersonDTO>(salePersonRule2);
            Expression<Func<CarDTO, SalesPersonDTO, bool>> compositeRule
                = carRule1Expression.Or(salePersonRuleExpression1).Or(salePersonRuleExpression2);

            Assert.AreEqual(true, compositeRule.Compile()(car, salesperson));
        }
        public void TuplesLoadFromFile()
        {
            // rule DTO
            var car = new CarDTO
            {
                Make = "Ford",
                Year = 2010,
                Model = "Expedition",
                AskingPrice = 10000.0000m,
                SellingPrice = 9000.0000m
            };

            var salesperson = new SalesPersonDTO
            {
                State = "PA",
                IsManager = true,
                MaximumDiscount = 1000.0000m
            };

            // Load all rules applied to the user type.
            var re = new TupleRuleEngine();
            var xd = new XmlDocument();
            xd.Load(@"C:\development\RuleEngine\TinyTuleEngineUnitTest\TupleRuleEngineTest\RuleSetTuple.xml");
            re.LoadRulesFromElementList<CarDTO,SalesPersonDTO>(xd, "/rules/rule");

            Func<CarDTO, SalesPersonDTO, bool> fordSaleApproverWithSalesPersonInfo = re.GetRule<CarDTO,SalesPersonDTO>("FordSaleApproverWithSalesPersonInfo").Compile();
            Assert.AreEqual(true, fordSaleApproverWithSalesPersonInfo(car, salesperson));
        }
        public List <SalesPersonDTO> GetSalesperson(int districtId)
        {
            using (var con = new SqlConnection(_connectionString))
            {
                string Command = "SELECT S.SPId, S.Firstname,S.Lastname,S.Description, DS.Position, DS.DistrictSalespersonId FROM Salesperson AS S, DistrictSalesperson AS DS, District AS D WHERE DS.DistrictId = @districtId AND D.DistrictId = DS.DistrictId AND S.SPId = DS.SPId";
                var    cmd     = new SqlCommand(Command, con);
                cmd.Parameters.AddWithValue("@districtId", districtId);
                con.Open();
                var salesPersonList = new List <SalesPersonDTO>();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var salesPerson = new SalesPersonDTO();
                            salesPerson.SPId                  = reader.GetInt32(0);
                            salesPerson.Firstname             = reader.GetString(1);
                            salesPerson.Lastname              = reader.GetString(2);
                            salesPerson.Description           = reader.GetString(3);
                            salesPerson.Position              = reader.GetString(4);
                            salesPerson.DistrictSalespersonId = reader.GetInt32(5);

                            salesPersonList.Add(salesPerson);
                        }

                        reader.NextResult();
                    }
                }
                return(salesPersonList);
            }
        }
Example #4
0
 public async Task <IHttpActionResult> PutSalesPerson(int entityId, SalesPersonDTO value)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         if (value.EntityId != entityId)
         {
             return(BadRequest());
         }
         DbContext.Entry(value).State = EntityState.Modified;
         try
         {
             await DbContext.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!ValueExists(entityId))
             {
                 return(NotFound());
             }
             throw;
         }
         return(StatusCode(HttpStatusCode.NoContent));
     }
     catch (Exception ex)
     {
         Log.Error("SalesPerson.Put: " + ex);
         throw;
     }
 }
Example #5
0
        public static int Compare(SalesPerson lhs, SalesPersonDTO rhs)
        {
            if (ReferenceEquals(lhs, null))
            {
                return(-1);
            }

            if (ReferenceEquals(rhs, null))
            {
                return(1);
            }

            return(lhs.EntityId.CompareTo(lhs.EntityId));
        }
Example #6
0
 public static SalesPerson ReadFromDTO(SalesPerson target, SalesPersonDTO source)
 {
     target.EntityId = source.EntityId;
     PersonTX.ReadFromDTO(target.Person, source.Person);
     SalesTerritoryTX.ReadFromDTO(target.SalesTerritory, source.SalesTerritory);
     target.SalesTerritoryId = source.SalesTerritoryId;
     target.SalesQuota       = source.SalesQuota;
     target.Bonus            = source.Bonus;
     target.CommissionPct    = source.CommissionPct;
     target.SalesYTD         = source.SalesYTD;
     target.SalesLastYear    = source.SalesLastYear;
     target.ModifiedDate     = source.ModifiedDate;
     return(target);
 }
Example #7
0
        public async Task <IHttpActionResult> PostSalesPerson(SalesPersonDTO value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                DbContext.SalesPersons.Add(SalesPersonTX.ReadFromDTO(new SalesPerson(), value));
                await DbContext.SaveChangesAsync();

                return(CreatedAtRoute("DefaultApi", new { EntityId = value.EntityId }, value));
            }
            catch (Exception ex)
            {
                Log.Error("SalesPerson.Post: " + ex);
                throw;
            }
        }
Example #8
0
        public List <SalesPersonDTO> GetAllSalesperson()
        {
            List <SalesPersonDTO> salespersonList = new List <SalesPersonDTO>();

            String        query      = "SELECT slpCode, slpName FROM OSLP";
            SqlCommand    command    = new SqlCommand(query, sqlServerConnection);
            SqlDataReader dataReader = command.ExecuteReader();

            while (dataReader.Read())
            {
                SalesPersonDTO salesperson = new SalesPersonDTO();
                salesperson.slpCode = (short)dataReader["slpCode"];
                salesperson.slpName = (String)dataReader["slpName"];

                salespersonList.Add(salesperson);
            }
            dataReader.Close();

            return(salespersonList);
        }
Example #9
0
        public IActionResult Create([FromBody] SalesPersonDTO salespersonDTO)
        {
            SalesPerson salesperson = new SalesPerson();

            salesperson.SalesPersonId = Guid.NewGuid();
            salesperson.FirstName     = salespersonDTO.FirstName;
            salesperson.Address       = salespersonDTO.Address;
            salesperson.IsActive      = salespersonDTO.IsActive;
            salesperson.LastName      = salespersonDTO.LastName;
            salesperson.MobileNo      = salespersonDTO.MobileNo;
            salesperson.Password      = salespersonDTO.PhoneNo;
            salesperson.PhoneNo       = salespersonDTO.PhoneNo;
            salesperson.Salary        = salespersonDTO.Salary;
            salesperson.UserName      = salespersonDTO.UserName;


            var salepersonEntity = _salespersonService.Create(salesperson);
            var sales            = _mapper.Map <SalesPersonDTO>(salepersonEntity);


            return(Ok(salesperson));
        }
        public void IdentityTupleBasicOperatorTest()
        {
            // rule DTO
            var car = new CarDTO
            {
                Make = "Ford",
                Year = 2010,
                Model = "Expedition",
                AskingPrice = 10000.0000m,
                SellingPrice = 9000.0000m
            };

            var salesperson = new SalesPersonDTO
            {
                State = "PA",
                IsManager = true,
                MaximumDiscount = 1000.0000m
            };

            // programatic mix in of claims rule and rule against the DTO for Car and SalesPerson
            var carRule1 = new Rule("Year", "2010", "GreaterThanOrEqual","CarDTO");
            var claimRule = new Rule("@User", "S-1-5-21-2493390151-660934664-2262481224-513", "http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid");
            var salePersonRule1 = new Rule("State", "PA", "Equals","SalesPersonDTO");
            var salePersonRule2 = new Rule("IsManager", "true", "Equals", "SalesPersonDTO");

            var re = new IdentityTupleRuleEngine();

            // build Some Expressions
            Expression<Func<CarDTO, SalesPersonDTO,IClaimsPrincipal, bool>> carRule1Expression = re.GetExpression<CarDTO,SalesPersonDTO>(carRule1);
            Expression<Func<CarDTO, SalesPersonDTO, IClaimsPrincipal, bool>> claimRuleExpression = re.GetExpression<CarDTO, SalesPersonDTO>(claimRule);
            Expression<Func<CarDTO, SalesPersonDTO, IClaimsPrincipal, bool>> sp1Expression = re.GetExpression<CarDTO, SalesPersonDTO>(salePersonRule1);
            Expression<Func<CarDTO, SalesPersonDTO, IClaimsPrincipal, bool>> sp2Expression = re.GetExpression<CarDTO, SalesPersonDTO>(salePersonRule2);

            Expression<Func<CarDTO, SalesPersonDTO, IClaimsPrincipal, bool>> coumpoundExpr =
                carRule1Expression.Or(claimRuleExpression).Or(sp1Expression).Or(sp2Expression);

            IClaimsPrincipal id = new ClaimsPrincipal(System.Threading.Thread.CurrentPrincipal);
            Assert.AreEqual(true, coumpoundExpr.Compile()(car,salesperson,id));
        }
Example #11
0
        public async Task <IHttpActionResult> GetSalesPerson(int entityId)
        {
            try
            {
                SalesPersonDTO found = await Task.Run(() =>
                {
                    return(SalesPersonTX.WriteToDTO(DbContext.SalesPersons
                                                    .AsEnumerable().FirstOrDefault(e => e.EntityId == entityId)));
                });

                if (found == null)
                {
                    return(NotFound());
                }
                return(Ok(found));
            }
            catch (Exception ex)
            {
                Log.Error("SalesPerson.Get: " + ex);
                throw;
            }
        }
Example #12
0
 public static int Compare(SalesPersonDTO lhs, SalesPerson rhs)
 {
     return(Compare(rhs, lhs) * -1);
 }