Exemple #1
0
        public ActionResult <KeysPreview> GetLicensesByConsultant()
        {
            try
            {
                KeysPreview preview = _sendKey.GetKeysByConsuntant(Convert.ToInt32(_user));
                preview.Success = true;

                return(preview);
            }
            catch (SqlException ex)
            {
                return(new KeysPreview()
                {
                    Code = "SQL",
                    Success = false,
                    Message = ex.Message
                });
            }
            catch (System.Exception ex)
            {
                return(new KeysPreview()
                {
                    Code = "SQL",
                    Success = false,
                    Message = ex.Message
                });
            }
        }
Exemple #2
0
        public KeysPreview GetKeysByConsuntant(int consultant)
        {
            KeysPreview list = new KeysPreview();
            List <Key>  keys = new List <Key>();

            using (SqlConnection Con = new SqlConnection(_connStr.Value.SqlServer))
            {
                using (SqlCommand Cmd = new SqlCommand())
                {
                    Cmd.CommandType = CommandType.StoredProcedure;
                    Cmd.Connection  = Con;
                    Cmd.CommandText = "[spGetLicensesByConsultant]";

                    Cmd.Parameters.AddWithValue("@ConsultantId", consultant);

                    Con.Open();

                    using (SqlDataReader reader = Cmd.ExecuteReader())
                    {
                        reader.Read();

                        list.Total = reader.GetInt32(0);

                        reader.NextResult();

                        reader.Read();

                        list.Available = reader.GetInt32(0);

                        reader.NextResult();

                        while (reader.Read())
                        {
                            Key key = new Key()
                            {
                                Guid        = reader.GetGuid(0).ToString(),
                                Email       = reader.GetString(1),
                                SentWhen    = reader.GetDateTime(2),
                                Started     = reader.GetDateTime(3),
                                Finished    = reader.GetDateTime(4),
                                BlockResult = reader.GetBoolean(5),
                                Name        = reader.GetString(6)
                            };

                            keys.Add(key);
                        }
                    }
                }
            }

            list.Keys = keys;

            return(list);
        }