public void ValidateSanctionTypeCost(SanctionType sanctionType)
 {
     if (sanctionType.Cost <= 0)
     {
         throw new BusinessException(2);
     }
 }
示例#2
0
        private void CheckLicenseDetails(string response)
        {
            //Get license dates
            //Some providers have multiple licenses
            MatchCollection exp = Regex.Matches(response, "(Until|Date|Expire[ds]):</b></td><td>(?<date>\\d+/\\d+/\\d+)", RegOpt);

            //We make the assumption that the license higher up in the list is the more recent one
            //The website appears to follow this trend
            if (exp.Count > 0)
            {
                Expiration = exp[0].Groups["date"].Value;
            }

            //Get sanction status
            Match sanction = Regex.Match(response, "Board Action\\?</b></td><td>Yes", RegOpt);

            //The regex specifically looks for sanctions
            if (sanction.Success)
            {
                Sanction = SanctionType.Red;
            }
            else
            {
                Sanction = SanctionType.None;
            }
        }
        public BaseEntity BuildObject(Dictionary <string, object> row)
        {
            var Company = new Company
            {
                IdCompany = GetIntValue(row, IDCOMPANY)
            };

            var Route = new Route
            {
                IdRoute = GetIntValue(row, IDROUTE)
            };

            var Terminal = new Terminal
            {
                IdTerminal = GetIntValue(row, IDTERMINAL)
            };

            var SanctionType = new SanctionType
            {
                IdType = GetIntValue(row, IDSANCTIONTYPE)
            };

            var Sanction = new Sanction
            {
                IdSanction  = GetIntValue(row, IDSANCTION),
                Date        = GetStringValue(row, DATE),
                Description = GetStringValue(row, DESCRIPTION),
                Company     = Company,
                Route       = Route,
                Terminal    = Terminal,
                Type        = SanctionType
            };

            return(Sanction);
        }
 public SanctionCancelledEvent(string brokenRule, SanctionType sanctionType, string username, int userId)
 {
     BrokenRule   = brokenRule;
     SanctionType = sanctionType;
     Username     = username;
     UserId       = userId;
 }
示例#5
0
        private void CheckLicenseDetails(string response)
        {
            //If they have multiple licenses, we return the expiration date of the license searched for
            Match exp = Regex.Match(response, "<b>Expiration\\s+Date:(</b></span>){3}</td>\\s+<td width=\"\\d+\"><span id=\"[_\\w]+\" class=\"normal\"( style=\"[;:\\w]+\")?>(?<date>\\d+-\\d+-\\d+)</span>", RegOpt);

            //Set the expiration date to the expiration date of the latest one
            if (exp.Success)
            {
                Expiration = exp.Groups["date"].Value;
            }

            //Site has sections for disciplinary action and corrective action
            Match disc = Regex.Match(response, "Disciplinary Action:[:;_\"=/<>\\w\\s]+No</span></td>\\s+<td vAlign", RegOpt);
            Match corr = Regex.Match(response, "Corrective\\s+Action:[:;_\"=/<>\\w\\s]+No</span></td>\\s+</tr>", RegOpt);

            //We check for the absence of disciplinary/corrective action
            if (disc.Success && corr.Success)
            {
                Sanction = SanctionType.None;
            }
            else
            {
                Sanction = SanctionType.Red;
            }
        }
示例#6
0
        private void CheckLicenseDetails(string response)
        {
            //Get license dates
            MatchCollection exp = Regex.Matches(response, "<td align=\"center\">(\\d*/\\d*/\\d*)</td>", RegOpt);

            //There are two dates in the form data: one for date issued and one for expiration,
            //but they do not have id tags to differentiate them
            if (exp.Count == 2)
            {
                Expiration = exp[1].Groups[1].ToString();
            }

            //Get sanction status
            Match sanction = Regex.Match(response, "<td style=\"padding-left:5px;\">Disciplinary Action</td>\n*\\s*<td style=\"padding-left:5px;\">\n*\\s*(N)", RegOpt);

            //The regex specifically looks for no sanctions
            if (sanction.Success)
            {
                Sanction = SanctionType.None;
            }
            else
            {
                Sanction = SanctionType.Red;
            }
        }
示例#7
0
 private void CheckSanctions(int userId, SanctionType sanctionType)
 {
     Ensure.Bool.IsFalse(_sanctionRepository.GetAllOfUser(userId).ToList()
                         .Exists(s => s.Type.Equals(sanctionType) && s.IsActive), nameof(CheckSanctions),
                         opt => opt.WithException(
                             new ActionIsNotAllowWithSanctionsException(SanctionType.NotAllowToEditProfile)));
 }
示例#8
0
        private void CheckLicenseDetails(string response)
        {
            //Ensure we get the expiration date of the license
            Match exp = Regex.Match(response, "Expiration Date</span><[-='\\w ]+><span[-='\\w ]+>(?<date>[,\\w ]+)", RegOpt);

            //Set the expiration date
            try
            {
                Expiration = Convert.ToDateTime(exp.Groups["date"].Value).ToShortDateString();
            } catch (FormatException e)
            {
                Expiration = "01/01/1492";
            }

            //Disciplinary action
            Match disc = Regex.Match(response, "No cases", RegOpt);

            //We check for the absence of disciplinary/corrective action
            if (disc.Success)
            {
                Sanction = SanctionType.None;
            }
            else
            {
                Sanction = SanctionType.Red;
            }
        }
示例#9
0
        private void CheckLicenseDetails(string response)
        {
            //Ensure we get the expiration date of the license
            Match exp = Regex.Match(response, "td\\s+headers=\"CURRENT_EXP_DATE_\\d+\">(?<date>[#&;\\w]+)</td>", RegOpt);

            //Set the expiration date
            try
            {
                Expiration = Convert.ToDateTime(CleanDate(exp.Groups["date"].Value)).ToShortDateString();
            } catch (FormatException e)
            {
                Expiration = "01/01/1492";
            }

            //Disciplinary action
            Match disc = Regex.Match(response, "<td\\s+headers=\"C\\d+_\\d+\">N</td>", RegOpt);

            //We check for the absence of disciplinary/corrective action
            if (disc.Success)
            {
                Sanction = SanctionType.None;
            }
            else
            {
                Sanction = SanctionType.Red;
            }
        }
示例#10
0
        private Result <string> ParseResponse(string response)
        {
            try
            {
                // get div with result
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(response);

                var      startNode      = doc.DocumentNode.SelectNodes("//comment()[contains(., 'End Pages')]").First();
                var      endNode        = doc.DocumentNode.SelectNodes("//comment()[contains(., 'Pages')]").Reverse().Skip(1).FirstOrDefault();
                int      startNodeIndex = startNode.ParentNode.ChildNodes.IndexOf(startNode);
                int      endNodeIndex   = endNode.ParentNode.ChildNodes.IndexOf(endNode);
                var      nodes          = startNode.ParentNode.ChildNodes.Where((n, index) => index >= startNodeIndex && index <= endNodeIndex).Select(n => n);
                HtmlNode resultTab      = nodes.Where((n) => n.Name.Contains("div")).FirstOrDefault();

                // gather data
                string fullName          = Regex.Match(resultTab.InnerHtml, "(?<=strong><span.*>).*(?=</span></strong>)", RegOpt).ToString();
                string practiceLocations = Regex.Match(resultTab.InnerHtml, "(?<=Locations.*>).*(?=<br>.*<strong)", RegOpt).ToString();
                string participatingS    = string.Empty;
                Match  participating     = Regex.Match(resultTab.InnerHtml, "Participating", RegOpt);
                if (participating.Success)
                {
                    participatingS = participating.ToString();
                }
                var headerMatches = Regex.Matches(resultTab.InnerHtml, "(?<=<th.*;.>)[\\w,\\s]*(?=)", RegOpt);
                var valueMatches  = Regex.Matches(resultTab.InnerHtml, "(?<=td>)[^<]*(?=</td>)", RegOpt);

                // form return table
                StringBuilder builder = new StringBuilder();
                builder.AppendFormat(TdPair, "Full Name", fullName);
                builder.AppendFormat(TdPair, "Practice Locations", practiceLocations);
                if (participatingS != string.Empty)
                {
                    builder.AppendFormat(TdPair, "Participating in MOC", "yes");
                }
                else
                {
                    builder.AppendFormat(TdPair, "Participating in MOC", "no");
                }
                for (var i = 0; i < valueMatches.Count; i++)
                {
                    // if a license is expired
                    if (valueMatches[i].ToString().Contains("Expired"))
                    {
                        Sanction = SanctionType.Red;
                    }

                    // append key value pairs
                    builder.AppendFormat(TdPair, headerMatches[i % headerMatches.Count].ToString(), valueMatches[i].ToString());
                }


                return(Result <string> .Success(builder.ToString()));
            }
            catch (Exception e)
            {
                return(Result <string> .Exception(e));
            }
        }
 public SanctionsAppliedToAdminMessage(string brokenRule, SanctionType sanctionType, string userName,
                                       string receiverName)
 {
     BrokenRule   = brokenRule;
     SanctionType = sanctionType;
     UserName     = userName;
     ReceiverName = receiverName;
 }
示例#12
0
 public Sanction(string brokenRule, int userId, int moderatorId, SanctionType type)
 {
     BrokenRule  = brokenRule;
     UserId      = userId;
     ModeratorId = moderatorId;
     Type        = type;
     IsActive    = true;
     IsTemporary = false;
 }
示例#13
0
        private Result <string> ParseResponse(string response)
        {
            // DECLARATIONS
            HtmlDocument  doc     = new HtmlDocument();
            HtmlDocument  parent  = new HtmlDocument();
            HtmlDocument  table   = new HtmlDocument();
            List <string> hList   = new List <string>();
            List <string> vList   = new List <string>();
            StringBuilder builder = new StringBuilder();

            // GET ROWS WITH HEADERS AND VALUES
            doc.LoadHtml(response);
            parent.LoadHtml(doc.GetElementbyId("ContentPlaceHolder2_LData").InnerHtml);
            table.LoadHtml(parent.DocumentNode.SelectNodes("//table[@class='tablestyle13']").Last().InnerHtml);
            var rows = table.DocumentNode.SelectNodes("//tr");

            // ISOLATE HEADERS AND DATA
            foreach (var row in rows)
            {
                if (row.ChildNodes.Count > 1)
                {
                    if (row.Attributes.Count > 0 && row.Attributes["class"].Value.Contains("trstyle3"))
                    {
                        foreach (var header in row.ChildNodes)   // is the header row
                        {
                            if (header.InnerText != string.Empty)
                            {
                                hList.Add(header.InnerText);
                            }
                        }
                    }
                    else
                    {
                        foreach (var value in row.ChildNodes)   // is the value row
                        {
                            vList.Add(value.InnerText);
                        }
                    }
                }
            }

            // FORM THE DATA
            for (var i = 0; i < hList.Count; i++)
            {
                if (hList[i].Contains("Disciplinary") && vList[i].Contains("Yes"))
                {
                    Sanction = SanctionType.Red;
                }
                builder.AppendFormat(TdPair, hList[i], vList[i]);
                builder.AppendLine();
            }


            return(Result <string> .Success(builder.ToString()));
        }
示例#14
0
 public Sanction(string brokenRule, int userId, int moderatorId, SanctionType type,
                 DateTimeOffset expirationDate)
 {
     BrokenRule     = brokenRule;
     UserId         = userId;
     ModeratorId    = moderatorId;
     Type           = type;
     IsActive       = true;
     IsTemporary    = true;
     ExpirationDate = expirationDate;
 }
示例#15
0
 public SanctionModel(string brokenRule, int userId, string userName, int moderatorId, bool isTemporary,
                      DateTimeOffset expirationDate, SanctionType type, bool isActive)
 {
     BrokenRule     = brokenRule;
     UserId         = userId;
     UserName       = userName;
     ModeratorId    = moderatorId;
     IsTemporary    = isTemporary;
     ExpirationDate = expirationDate;
     Type           = type;
     IsActive       = isActive;
 }
示例#16
0
 internal Sanction(int id, string brokenRule, int userId,
                   int moderatorId, bool isTemporary, DateTimeOffset expirationDate, SanctionType type, bool isActive)
 {
     Id             = id;
     BrokenRule     = brokenRule;
     UserId         = userId;
     ModeratorId    = moderatorId;
     IsTemporary    = isTemporary;
     ExpirationDate = expirationDate;
     Type           = type;
     IsActive       = isActive;
 }
 public void UpdateSanctionType(SanctionType type)
 {
     try
     {
         ValidateFields(type);
         ValidateSanctionTypeCost(type);
         CrudFactory.UpdateSanctionType(type);
     }
     catch (Exception bex)
     {
         ExceptionManager.GetInstance().Process(bex);
     }
 }
示例#18
0
        private void CheckLicenseDetails(string response)
        {
            Match exp = Regex.Match(response, "Status: </b>(?<EXP>.*?)<br>", RegOpt);

            if (exp.Success)
            {
                Expiration = exp.Groups["EXP"].ToString();
                if (Expiration != "Active")
                {
                    Sanction = SanctionType.Red;
                }
            }
        }
示例#19
0
        private void CheckLicenseDetails(string response)
        {
            Match ACT = Regex.Match(response, "Status:</strong>(?<ACT>.*)<br");

            if (ACT.Success)
            {
                string activity = ACT.Groups["ACT"].ToString();
                if (!activity.Contains("Active"))
                {
                    Sanction = SanctionType.Red;
                }
            }
        }
示例#20
0
        public BaseEntity BuildObject(Dictionary <string, object> row)
        {
            var Type = new SanctionType
            {
                IdType      = GetIntValue(row, IDTYPE),
                Name        = GetStringValue(row, NAME),
                Description = GetStringValue(row, DESCRIPTION),
                Cost        = GetDoubleValue(row, COST),
                Status      = GetIntValue(row, STATUS)
            };

            return(Type);
        }
示例#21
0
        private Result <string> ParseResponse(string response)
        {
            var doc = new HtmlDocument();

            doc.LoadHtml(response);
            var body = doc.DocumentNode.SelectSingleNode("//body");

            if (body.InnerHtml != String.Empty)
            {
                //declarations
                StringBuilder   builder = new StringBuilder();
                MatchCollection dataRgx = Regex.Matches(body.InnerHtml, @"(?<=ctl.*>+).*(?=</span)", RegOpt);
                List <string>   data    = new List <string>();

                for (var i = 0; i < dataRgx.Count - 1; i += 2)
                {
                    if (dataRgx[i + 1].ToString() != "")
                    {
                        data.Add(dataRgx[i].ToString());
                        data.Add(dataRgx[i + 1].ToString());
                    }
                }


                //handle data
                for (var j = 0; j < data.Count - 1; j += 2)
                {
                    if (data[j].Contains("Expiry"))
                    {
                        Expiration = data[j + 1];
                    }
                    builder.AppendFormat(TdPair, data[j], data[j + 1]);
                    builder.AppendLine();
                }


                //handle sanctions
                if (Regex.Match(response, "Has Discipline").Success)
                {
                    Sanction = SanctionType.Red;
                }



                return(Result <string> .Success(builder.ToString()));
            }
            else // Error parsing table
            {
                return(Result <string> .Failure(ErrorMsg.CannotAccessDetailsPage));
            }
        }
示例#22
0
        private void CheckLicenseDetails(string response)
        {
            Match exp = Regex.Match(response, "LicenseExpDate\" type=\"text\" value=\"(?<EXP>.*?)\" maxlength", RegOpt);

            Expiration = exp.Groups["EXP"].ToString();

            //Does not support sanctions
            Match GoodDiscipline = Regex.Match(response, "<span style=\"font-size: 120%\">None</span>", RegOpt);

            if (!GoodDiscipline.Success)
            {
                Sanction = SanctionType.Red;
            }
        }
        public bool ValidateIsNotExistingType(SanctionType sanctionType)
        {
            bool NotExists = true;

            SanctionType Name        = CrudFactory.RetrieveSanctionTypeByName <SanctionType>(sanctionType);
            SanctionType Description = CrudFactory.RetrieveSanctionTypeByDescription <SanctionType>(sanctionType);


            if (Name != null || Description != null)
            {
                NotExists = false;
            }

            return(NotExists);
        }
示例#24
0
        private void CheckLicenseDetails(string response)
        {
            data = Regex.Match(response, "<div[='\\w ]+>License Information</div><div>\\s*<table[-=:;\"\\w ]+>\\s*<thead>\\s*<tr[=\"\\w ]+>\\s*(<th[\"=\\w ]+>(?<header>[\\w ]+)</th>){7}\\s*</tr>\\s*</thead>\\s*<tbody>\\s*<tr[=\"\\w ]+>\\s*(<td>(?<value>[/\\w ]*)(&nbsp;)?</td>){7}\\s*</tr>\\s*</tbody>\\s*</table>", RegOpt);

            //Ensure we get the expiration date of the license
            Expiration = data.Groups["value"].Captures[5].Value;

            //We check for the absence of disciplinary/corrective action
            if (data.Groups["value"].Captures[6].Value == "N")
            {
                Sanction = SanctionType.None;
            }
            else
            {
                Sanction = SanctionType.Red;
            }
        }
示例#25
0
        private void CheckLicenseDetails(string response)
        {
            Match exp = Regex.Match(response, "Expirationdate2\">(?<EXP>.*?)</span>", RegOpt);

            if (exp.Success)
            {
                Expiration = exp.Groups["EXP"].ToString();
            }

            Match status = Regex.Match(response, "Licensestatus2\">(?<ACTION>.*?)</span>", RegOpt);

            if (status.Success)
            {
                Sanction = Regex.Match(status.Groups["ACTION"].ToString(), "None", RegOpt).Success ? SanctionType.None : SanctionType.Red;
                Sanction = Regex.Match(status.Groups["ACTION"].ToString(), "Active", RegOpt).Success&& !Regex.IsMatch(status.Groups["ACTION"].ToString(), "Not Active", RegOpt) ? SanctionType.None : SanctionType.Red;
            }
        }
示例#26
0
        private void CheckLicenseDetails(string response)
        {
            Match exp1 = Regex.Match(response, "License Expire(s|d)?.?</b></td><td.*?>(?<EXP>.*?)(<tr|</td)", RegOpt);
            Match exp2 = Regex.Match(response, "License Lapsed.?</b></td><td.*?>(?<EXP>.*?)(<tr|</td)", RegOpt);
            Match exp3 = Regex.Match(response, "Expiration Date.?</b></td><td.*?>(?<EXP>.*?)(<tr|</td)", RegOpt);

            if (exp1.Success)
            {
                Expiration = exp1.Groups["EXP"].ToString();
            }
            else if (exp2.Success)
            {
                Expiration = exp2.Groups["EXP"].ToString();
            }
            else if (exp3.Success)
            {
                Expiration = exp3.Groups["EXP"].ToString();
            }

            Match status1 = Regex.Match(response, "<b>Board Action.</b></td><td.*?>(?<ACTION>.*?)(<tr|</td)", RegOpt);
            Match status2 = Regex.Match(response, "<b>Has the Board taken action.*?</b></td><td.*?>(?<ACTION>.*?)(<tr|</td)");
            Match status3 = Regex.Match(response, "<b>(Publicly )?Disciplined.*?</b></td><td.*?>(?<ACTION>.*?)(<tr|</td)");

            if (status1.Success)
            {
                Sanction = Regex.Match(status1.Groups["ACTION"].ToString(), "There has been no.", RegOpt).Success ? SanctionType.None : SanctionType.Red;
            }
            else if (status2.Success)
            {
                Sanction = Regex.Match(status2.Groups["ACTION"].ToString(), "nochecked.gif", RegOpt).Success ? SanctionType.None : SanctionType.Red;
            }
            else if (status3.Success)
            {
                Sanction = Regex.Match(status3.Groups["ACTION"].ToString(), "nochecked.gif", RegOpt).Success ? SanctionType.None : SanctionType.Red;
            }

            if (Sanction == SanctionType.None) // Check again in Malpractice actions - (if section exists)
            {
                Match action = Regex.Match(response, "<b>Malpractice Action:</b></td><td.*?>(?<ACTION>.*?)(<tr|</td)", RegOpt);
                if (action.Success)
                {
                    Sanction = Regex.Match(action.Groups["ACTION"].ToString(), "There has been no reported malpractice on this license", RegOpt).Success ? SanctionType.None : SanctionType.Red;
                }
            }
        }
        public IHttpActionResult DeleteSanctionType(SanctionType type)
        {
            try
            {
                var Mngr = new SanctionManager();
                Mngr.DeleteSanctionType(type);

                ApiResp = new ApiResponse
                {
                    Message = "Tipo eliminado exitosamente"
                };

                return(Ok(ApiResp));
            }
            catch (BusinessException bex)
            {
                return(InternalServerError(new Exception(bex.ExceptionId + "-" + bex.AppMessage.Message)));
            }
        }
        public void CreateSanctionType(SanctionType sanctionType)
        {
            try
            {
                ValidateFields(sanctionType);
                ValidateSanctionTypeCost(sanctionType);

                if (ValidateIsNotExistingType(sanctionType))
                {
                    CrudFactory.CreateSanctionType(sanctionType);
                }
                else
                {
                    throw new BusinessException(3);
                }
            }
            catch (Exception bex)
            {
                ExceptionManager.GetInstance().Process(bex);
            }
        }
示例#29
0
        public int AddSanction(string brokenRule, int userId, int moderatorId, SanctionType type)
        {
            Ensure.String.IsNotNullOrWhiteSpace(brokenRule);
            Ensure.Any.IsNotNull(type);
            Ensure.Any.IsNotNull(_userRepository.GetUserById(userId), nameof(AddSanction),
                                 opt => opt.WithException(new UserNotFoundException(userId)));
            Ensure.Bool.IsTrue(_userRepository.GetUserById(moderatorId).Type.Equals(UserType.Moderator) ||
                               _userRepository.GetUserById(moderatorId).Type.Equals(UserType.Admin),
                               nameof(AddSanction),
                               opt => opt.WithException(new NotEnoughPermissionsException(moderatorId)));

            var suspectedUser = _userRepository.GetUserById(userId);
            var sanction      = new Sanction(brokenRule, userId, moderatorId, type);

            _sanctionRepository.Add(sanction);

            _publisher.PublishEvent(new SanctionsAppliedEvent(brokenRule, type, suspectedUser.UserProfile.Name,
                                                              userId));

            return(sanction.Id);
        }
示例#30
0
        private Result <string> ParseResponse(List <String> response)
        {
            List <String> headers = new List <String>();

            headers.Add("LASTNAME");
            headers.Add("FIRSTNAME");
            headers.Add("INITIAL");
            headers.Add("LICENSE #");
            headers.Add("DATE ISSUED");
            headers.Add("EXPIRATION DATE");
            headers.Add("License/Certificate Status");
            headers.Add("Disciplined");

            try
            {
                // check discipline
                if (string.Equals(response[response.Count - 1], "Yes", StringComparison.OrdinalIgnoreCase))
                {
                    Sanction = SanctionType.Red;
                }
                else
                {
                    Sanction = SanctionType.None;
                }

                StringBuilder builder = new StringBuilder();

                for (var i = 0; i < response.Count; i++)
                {
                    builder.AppendFormat(TdPair, headers[i], response[i]);
                    builder.AppendLine();
                }

                return(Result <string> .Success(builder.ToString()));
            }
            catch
            {
                return(Result <string> .Failure(ErrorMsg.Custom("Error reading results")));
            }
        }