Beispiel #1
0
        public static async Task <string> GetInfoCommandAsync(Command command)
        {
            try
            {
                using (InfoCommandContext db = new InfoCommandContext())
                {
                    var result = await db.InfoCommandTable.AsQueryable().Where(x =>
                                                                               x.CommandName.ToLower() == command.CommandName.ToLower())
                                 .FirstOrDefaultAsync();

                    if (result != null)
                    {
                        return(result.CommandContent);
                    }
                    else
                    {
                        return(string.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.StorageException, ex);
                throw;
            }
        }
Beispiel #2
0
        public static async Task <bool> DeleteInfoCommandAsync(string name)
        {
            try
            {
                using (InfoCommandContext db = new InfoCommandContext())
                {
                    var cmd = await db.InfoCommandTable.AsQueryable().Where(x => x.CommandName.ToLower() == name).FirstOrDefaultAsync();

                    if (cmd != null)
                    {
                        db.InfoCommandTable.Remove(cmd);
                        await db.SaveChangesAsync();

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException($"{typeof(StorageManager).GetType().FullName}: {ExceptionManager.GetAsyncMethodName()}", ex);
                throw;
            }
        }
Beispiel #3
0
        public static List <string> GetInfoCommands()
        {
            List <string> result = new List <string>();

            try
            {
                using (InfoCommandContext db = new InfoCommandContext())
                {
                    foreach (var element in db.InfoCommandTable)
                    {
                        result.Add(element.CommandName);
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.StorageException, ex);
                throw;
            }
        }
Beispiel #4
0
        public static async Task <bool> StoreInfoCommandAsync(Command command)
        {
            try
            {
                using (InfoCommandContext db = new InfoCommandContext())
                {
                    var cmd = await db.InfoCommandTable.AsQueryable().FirstOrDefaultAsync(x => x.CommandName.ToLower() == command.CommandName.ToLower());

                    if (cmd == null)
                    {
                        await db.InfoCommandTable.AddAsync(new InfoCommandTable
                        {
                            CommandName    = command.CommandName,
                            CommandContent = command.CommandContent
                        });

                        await db.SaveChangesAsync();

                        return(false);
                    }
                    else
                    {
                        cmd = new InfoCommandTable
                        {
                            CommandName    = command.CommandName,
                            CommandContent = command.CommandContent
                        };

                        await db.SaveChangesAsync();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ErrMessages.StorageException, ex);
                throw;
            }
        }