Ejemplo n.º 1
0
        /// <summary>
        /// Updates a user's criteria settings
        /// </summary>
        /// <param name="model">UserCriteriaModel</param>
        /// <param name="db">BridgeCareContext</param>
        public void SaveUserCriteria(UserCriteriaModel model, BridgeCareContext db)
        {
            if (!db.UserCriteria.Any(criteria => criteria.USERNAME == model.Username))
            {
                log.Error($"No user found with username {model.Username}.");
                throw new RowNotInTableException($"No user found with username {model.Username}.");
            }
            var userCriteria = db.UserCriteria.Single(criteria => criteria.USERNAME == model.Username);

            model.UpdateUserCriteria(userCriteria);
            db.SaveChanges();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get BRKey and BMSId pairs in form of InventorySelectionModels, if they match the provided user's criteria.
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        public List <InventorySelectionModel> GetInventorySelectionModels(BridgeCareContext db, UserInformationModel userInformation)
        {
            var userCriteriaEntity = db.UserCriteria.Where(criteria => criteria.USERNAME == userInformation.Name).First();
            var userCriteria       = new UserCriteriaModel(userCriteriaEntity);

            if (!userCriteria.HasAccess)
            {
                throw new UnauthorizedAccessException($"User {userInformation.Name} has no inventory access.");
            }

            string query = "SELECT CAST(BRKEY AS VARCHAR) as BRKey, BRIDGE_ID as BMSId FROM PennDot_Report_A ORDER BY CONVERT(INT, BRKey) ASC";

            if (userCriteria.HasCriteria)
            {
                string networkId = db.NETWORKS.FirstOrDefault().NETWORKID.ToString();
                query = ConstructInventoryQuery(userCriteria.Criteria, networkId);
            }

            return(db.Database
                   .SqlQuery <InventorySelectionModel>(query)
                   .AsQueryable()
                   .ToList());
        }
Ejemplo n.º 3
0
 public UserCriteriaEntity(UserCriteriaModel userCriteriaModel)
 {
     USERNAME   = userCriteriaModel.Username;
     CRITERIA   = userCriteriaModel.Criteria;
     HAS_ACCESS = userCriteriaModel.HasAccess;
 }
Ejemplo n.º 4
0
 public IHttpActionResult SetUserCriteria([FromBody] UserCriteriaModel userCriteria)
 {
     repo.SaveUserCriteria(userCriteria, db);
     return(Ok());
 }