Example #1
0
        /// <summary>
        /// Carrega o artigo pelo id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List <TargetActionGrant> LoadAllFrom(TargetAction na)
        {
            List <TargetActionGrant> lst = new List <TargetActionGrant>();

            SqlCommand sel = new SqlCommand();

            sel.CommandText = "SELECT awardid, grantedby, granted FROM " + Base.conf.prefix + "[newstargetactiongrant] WHERE id=@id ORDER BY granted";
            sel.Parameters.Add(new SqlParameter("@id", na.id));

            sel.Connection = Base.conf.Open();
            SqlDataReader rdr = sel.ExecuteReader();

            while (rdr.Read())
            {
                // Pega as informações

                TargetActionGrant nga = new TargetActionGrant(na);

                nga.awardidInt  = rdr.GetString(0);
                nga.grantedById = rdr.GetString(1);
                nga.granted     = rdr.GetDateTime(2);

                lst.Add(nga);
            }

            rdr.Close();
            sel.Connection.Close();

            return(lst);
        }
Example #2
0
        /// <summary>
        /// Cria novo
        /// </summary>
        public TargetActionGrant(TargetAction n)
        {
            actionInt = n;

            awardidInt   = "";
            grantedbyInt = "";
            grantedInt   = RacMsg.NullDateTime;
        }
Example #3
0
        /// <summary>
        /// Posição do call
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public int GetPosition(TargetAction n)
        {
            for (int i = 0; i < actions.Count; i++)
            {
                if (actions[i].id == n.id)
                {
                    return(i);
                }
            }

            return(-1);
        }
Example #4
0
        /// <summary>
        /// Carrega a lista de classes de licença para este sistema
        /// </summary>
        /// <returns></returns>
        List <TargetAction> ActionForTarget()
        {
            List <string>       ids = Base.conf.LoadStringList(id, "newstargetaction", "targetid", "id", "date");
            List <TargetAction> lst = new List <TargetAction>();

            for (int i = 0; i < ids.Count; i++)
            {
                TargetAction npc = new TargetAction(this);
                if (npc.Load(ids[i]))
                {
                    lst.Add(npc);
                }
            }

            return(lst);
        }
Example #5
0
        /// <summary>
        /// Salva a ticket
        /// </summary>
        /// <returns></returns>
        public static bool SaveAll(TargetAction na, List <TargetActionGrant> lst)
        {
            bool res = false;

            SqlCommand del = new SqlCommand();

            del.CommandText = "DELETE FROM " + Base.conf.prefix + "[newstargetactiongrant] WHERE id=@id";
            del.Parameters.Add(new SqlParameter("@id", na.id));

            del.Connection = Base.conf.Open();
            del.ExecuteNonQuery();
            del.Connection.Close();

            SqlCommand ins = new SqlCommand();

            ins.CommandText = "INSERT INTO " + Base.conf.prefix + "[newstargetactiongrant] (id, awardid, grantedby, granted) VALUES (@id, @awardid, @grantedby, @granted)";
            ins.Parameters.Add(new SqlParameter("@id", na.id));

            SqlParameter varAttribute = new SqlParameter("@awardid", "0");

            ins.Parameters.Add(varAttribute);

            SqlParameter varGrantedBy = new SqlParameter("@grantedby", "0");

            ins.Parameters.Add(varGrantedBy);

            SqlParameter varGranted = new SqlParameter("@granted", DateTime.Now);

            ins.Parameters.Add(varGranted);

            ins.Connection = Base.conf.Open();

            for (int i = 0; i < lst.Count; i++)
            {
                varAttribute.Value = lst[i].awardidInt;
                varGrantedBy.Value = lst[i].grantedbyInt;
                varGranted.Value   = lst[i].grantedInt;

                ins.ExecuteNonQuery();
            }

            ins.Connection.Close();

            return(res);
        }
Example #6
0
        public GenericStatusModel RegisterGrant(string token, [FromBody] RegisterGrant grant)
        {
            GenericStatusModel gsm = new GenericStatusModel();

            gsm.Result           = 0;
            gsm.ResultComplement = "";

            // Verifica o token de autenticação

            string machine = HttpContext.Features.Get <IHttpConnectionFeature>()?.RemoteIpAddress.ToString();

            string userId = SessionCode.ValidateSessionCode(token, machine);

            if (userId == null)
            {
                gsm.Result           = (int)RacMsg.Id.InvalidTokenInExpression;
                gsm.ResultComplement = "Token inválido";
            }

            LibVisLib.Profile prf = LibVisLib.Profile.LoadProfile(userId);
            if (prf == null)
            {
                gsm.Result           = (int)RacMsg.Id.InvalidTokenInExpression;
                gsm.ResultComplement = "Usuário não encontrado";
            }

            if (!prf.user.isInternal)
            {
                gsm.Result           = (int)RacMsg.Id.UserHasNoRightToThisItem;
                gsm.ResultComplement = "Usuário não tem direitos para essa ação";
            }

            if (gsm.Result == 0)
            {
                try
                {
                    if (!LibVisLib.Verify.AcceptGuidOrNull(grant.ActionId))
                    {
                        gsm.Result            = (int)RacLib.RacMsg.Id.Error;
                        gsm.ResultComplement += "Caracteres inválidos no id da ação; ";
                        RacLib.BaseLog.log.Log(RacLib.BaseLog.LogType.Error, "errActionId: Invalid chars");
                    }

                    if (!LibVisLib.Verify.AcceptGuidOrNull(grant.AwardId))
                    {
                        gsm.Result            = (int)RacLib.RacMsg.Id.Error;
                        gsm.ResultComplement += "Caracteres inválidos no id do premio; ";
                        RacLib.BaseLog.log.Log(RacLib.BaseLog.LogType.Error, "errActionId: Invalid chars");
                    }

                    if (grant.Add < 0 || grant.Add > 1)
                    {
                        gsm.Result            = (int)RacLib.RacMsg.Id.Error;
                        gsm.ResultComplement += "Ação inválida; ";
                        RacLib.BaseLog.log.Log(RacLib.BaseLog.LogType.Error, "errAdd: Invalid value");
                    }

                    if (gsm.Result == 0)
                    {
                        string actionId = LibVisLib.Verify.VerifyGuid(grant.ActionId);
                        string awardId  = LibVisLib.Verify.VerifyGuid(grant.AwardId);

                        LibVisLib.TargetAction trga = LibVisLib.TargetAction.LoadTargetAction(actionId);
                        if (trga == null)
                        {
                            gsm.Result            = (int)RacLib.RacMsg.Id.Error;
                            gsm.ResultComplement += "Ação inválida; ";
                            RacLib.BaseLog.log.Log(RacLib.BaseLog.LogType.Error, "errTargetId: Invalid target");
                        }
                        else
                        {
                            if (grant.Add == 0)
                            {
                                trga.RemoveGrant(grant.AwardId);
                            }
                            else
                            {
                                trga.AddGrant(grant.AwardId, userId);
                            }

                            trga.Save();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (!ex.Message.StartsWith("Thread was being aborted"))
                    {
                        gsm.Result            = (int)RacLib.RacMsg.Id.InternalError;
                        gsm.ResultComplement += ex.Message;
                        RacLib.BaseLog.log.Log(RacLib.BaseLog.LogType.InternalError, "Exception in form");
                        RacLib.BaseLog.log.Log(ex);
                    }
                }
            }

            return(gsm);
        }